Skip to content

Commit 6eed81e

Browse files
authored
Merge pull request #335 from Shopify/cbruckmayer/return-dedicated-exit-status
Return dedicated exit status
2 parents 9ee752d + 6518db3 commit 6eed81e

3 files changed

Lines changed: 22 additions & 7 deletions

File tree

ruby/lib/minitest/queue/build_status_reporter.rb

Lines changed: 15 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -108,7 +108,16 @@ def requeued_tests
108108
build.requeued_tests
109109
end
110110

111+
APPLICATION_ERROR_EXIT_CODE = 42
112+
TIMED_OUT_EXIT_CODE = 43
113+
TOO_MANY_FAILED_TESTS_EXIT_CODE = 44
114+
WORKERS_DIED_EXIT_CODE = 45
115+
SUCCESS_EXIT_CODE = 0
116+
TEST_FAILURE_EXIT_CODE = 1
117+
111118
def report
119+
exit_code = TEST_FAILURE_EXIT_CODE
120+
112121
if requeued_tests.to_a.any?
113122
step("Requeued #{requeued_tests.size} tests")
114123
requeued_tests.to_a.sort.each do |test_id, count|
@@ -131,10 +140,14 @@ def report
131140
if remaining_tests.size > 10
132141
puts " ..."
133142
end
143+
144+
exit_code = TIMED_OUT_EXIT_CODE
134145
elsif supervisor.time_left_with_no_workers.to_i <= 0
135146
puts red("All workers died.")
147+
exit_code = WORKERS_DIED_EXIT_CODE
136148
elsif supervisor.max_test_failed?
137149
puts red("Encountered too many failed tests. Test run was ended early.")
150+
exit_code = TOO_MANY_FAILED_TESTS_EXIT_CODE
138151
end
139152

140153
puts
@@ -146,9 +159,10 @@ def report
146159
puts red("Worker #{worker_id } crashed")
147160
puts error
148161
puts ""
162+
exit_code = APPLICATION_ERROR_EXIT_CODE
149163
end
150164

151-
success?
165+
success? ? SUCCESS_EXIT_CODE : exit_code
152166
end
153167

154168
def success?

ruby/lib/minitest/queue/runner.rb

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -258,20 +258,19 @@ def report_command
258258

259259
unless supervisor.exhausted?
260260
reporter = BuildStatusReporter.new(supervisor: supervisor)
261-
reporter.report
261+
exit_code = reporter.report
262262
reporter.write_failure_file(queue_config.failure_file) if queue_config.failure_file
263263
reporter.write_flaky_tests_file(queue_config.export_flaky_tests_file) if queue_config.export_flaky_tests_file
264264

265-
abort!("#{supervisor.size} tests weren't run.")
265+
abort!("#{supervisor.size} tests weren't run.", exit_code)
266266
end
267267
end
268268

269269
reporter = BuildStatusReporter.new(supervisor: supervisor)
270270
reporter.write_failure_file(queue_config.failure_file) if queue_config.failure_file
271271
reporter.write_flaky_tests_file(queue_config.export_flaky_tests_file) if queue_config.export_flaky_tests_file
272-
reporter.report
273-
274-
exit! reporter.success? ? 0 : 1
272+
exit_code = reporter.report
273+
exit! exit_code
275274
end
276275

277276
def report_grind_command

ruby/test/integration/minitest_redis_test.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -229,6 +229,7 @@ def test_max_test_failed
229229
end
230230

231231
refute_predicate $?, :success?
232+
assert_equal 44, $?.exitstatus
232233
assert_empty err
233234
expected = <<~EXPECTED
234235
Waiting for workers to complete
@@ -264,6 +265,7 @@ def test_all_workers_died
264265
end
265266

266267
refute_predicate $?, :success?
268+
assert_equal 40, $?.exitstatus
267269
assert_empty err
268270
expected = <<~EXPECTED
269271
Waiting for workers to complete
@@ -1018,7 +1020,7 @@ def test_application_error
10181020
assert_includes out, "Worker 1 crashed"
10191021
assert_includes out, "Some error in the test framework"
10201022

1021-
assert_equal 1, $?.exitstatus
1023+
assert_equal 42, $?.exitstatus
10221024
end
10231025

10241026
private

0 commit comments

Comments
 (0)