Skip to content

Commit 5fb5fde

Browse files
authored
Merge pull request #409 from Shopify/fix-bisect-inconclusive-exit-code
fix: do not exit non-zero on inconclusive bisect
2 parents 07074a2 + f7a10c5 commit 5fb5fde

2 files changed

Lines changed: 25 additions & 8 deletions

File tree

ruby/lib/minitest/queue/runner.rb

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,9 @@ def bisect_command
254254
step(yellow("The failing test was the first test in the test order so there is nothing to bisect."))
255255
File.write('log/test_order.log', "")
256256
File.write('log/bisect_test_details.log', "")
257-
exit! 1
257+
# Bisect ran successfully; there is simply nothing to bisect against.
258+
# Reserve non-zero exits for cases where the bisect could not run (see failing_test_present? above).
259+
exit! 0
258260
end
259261

260262
failing_order = queue.candidates
@@ -263,7 +265,10 @@ def bisect_command
263265
step(yellow("The bisection was inconclusive, there might not be any leaky test here."))
264266
File.write('log/test_order.log', "")
265267
File.write('log/bisect_test_details.log', "")
266-
exit! 1
268+
# Bisect ran successfully; the failure did not reproduce on the narrowed-down order.
269+
# This is the expected outcome for genuinely flaky tests (timing/async) rather than order-dependent ones.
270+
# Reserve non-zero exits for cases where the bisect could not run.
271+
exit! 0
267272
else
268273
step(green('The following command should reproduce the leak on your machine:'), collapsed: false)
269274
command = %w(bundle exec minitest-queue --queue - run)

ruby/test/integration/minitest_bisect_test.rb

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,12 @@ def setup
1111
end
1212

1313
def test_bisect
14+
result = nil
1415
out, err = capture_subprocess_io do
15-
run_bisect('log/leaky_test_order.log', 'LeakyTest#test_sensible_to_leak')
16+
result = run_bisect('log/leaky_test_order.log', 'LeakyTest#test_sensible_to_leak')
1617
end
1718

19+
assert_equal true, result, "bisect should exit 0 when a leaky test is identified"
1820
assert_empty filter_deprecation_warnings(err)
1921
expected_output = strip_heredoc <<-EOS
2022
--- Testing the failing test in isolation
@@ -101,10 +103,12 @@ def test_bisect
101103
end
102104

103105
def test_inconclusive
106+
result = nil
104107
out, err = capture_subprocess_io do
105-
run_bisect('log/unconclusive_test_order.log', 'LeakyTest#test_sensible_to_leak')
108+
result = run_bisect('log/unconclusive_test_order.log', 'LeakyTest#test_sensible_to_leak')
106109
end
107110

111+
assert_equal true, result, "inconclusive bisect should exit 0; it ran successfully and reported a valid diagnostic outcome"
108112
assert_empty filter_deprecation_warnings(err)
109113
expected_output = strip_heredoc <<-EOS
110114
--- Testing the failing test in isolation
@@ -178,10 +182,12 @@ def test_inconclusive
178182
end
179183

180184
def test_failing_test_is_the_first_entry_in_the_test_order
185+
result = nil
181186
out, err = capture_subprocess_io do
182-
run_bisect('log/unconclusive_test_order.log', 'LeakyTest#test_useless_0')
187+
result = run_bisect('log/unconclusive_test_order.log', 'LeakyTest#test_useless_0')
183188
end
184189

190+
assert_equal true, result, "should exit 0 when there is nothing to bisect; the run completed normally"
185191
assert_empty filter_deprecation_warnings(err)
186192
expected_output = strip_heredoc <<-EOS
187193
--- Testing the failing test in isolation
@@ -193,10 +199,12 @@ def test_failing_test_is_the_first_entry_in_the_test_order
193199
end
194200

195201
def test_broken_tests_which_are_not_evaluated_are_ignored
202+
result = nil
196203
out, err = capture_subprocess_io do
197-
run_bisect('log/leaky_with_broken_test_order.log', 'LeakyTest#test_sensible_to_leak')
204+
result = run_bisect('log/leaky_with_broken_test_order.log', 'LeakyTest#test_sensible_to_leak')
198205
end
199206

207+
assert_equal true, result, "inconclusive bisect should exit 0 even when broken tests are skipped along the way"
200208
assert_empty filter_deprecation_warnings(err)
201209
expected_output = strip_heredoc <<-EOS
202210
--- Testing the failing test in isolation
@@ -270,10 +278,12 @@ def test_broken_tests_which_are_not_evaluated_are_ignored
270278
end
271279

272280
def test_broken
281+
result = nil
273282
out, err = capture_subprocess_io do
274-
run_bisect('log/broken_test_order.log', 'LeakyTest#test_broken_test')
283+
result = run_bisect('log/broken_test_order.log', 'LeakyTest#test_broken_test')
275284
end
276285

286+
assert_equal true, result, "should exit 0 when the failing test fails in isolation; bisect ran and produced a useful diagnostic"
277287
assert_empty filter_deprecation_warnings(err)
278288
expected_output = strip_heredoc <<-EOS
279289
--- Testing the failing test in isolation
@@ -287,10 +297,12 @@ def test_broken
287297
end
288298

289299
def test_failing_test_is_not_present
300+
result = nil
290301
out, err = capture_subprocess_io do
291-
run_bisect('log/leaky_test_order.log', 'LeakyTestDoesNotExist#test_sensible_to_leak')
302+
result = run_bisect('log/leaky_test_order.log', 'LeakyTestDoesNotExist#test_sensible_to_leak')
292303
end
293304

305+
assert_equal false, result, "should exit non-zero when the failing test cannot be found; the run could not actually execute"
294306
assert_empty filter_deprecation_warnings(err)
295307
expected_output = strip_heredoc <<-EOS
296308
--- Testing the failing test in isolation

0 commit comments

Comments
 (0)