From 5fa2d3bccbc9f20b7fb8a49c5babd9023013b8b8 Mon Sep 17 00:00:00 2001 From: Zarif Mahfuz Date: Thu, 9 May 2024 17:32:43 -0600 Subject: [PATCH 1/2] Exit with special code upon unexpected error --- ruby/lib/minitest/queue.rb | 5 +++++ ruby/test/fixtures/test/bad_framework_test.rb | 14 +++++++++++++ ruby/test/integration/minitest_redis_test.rb | 21 +++++++++++++++++++ 3 files changed, 40 insertions(+) create mode 100644 ruby/test/fixtures/test/bad_framework_test.rb diff --git a/ruby/lib/minitest/queue.rb b/ruby/lib/minitest/queue.rb index 2b73ff00..c590b453 100644 --- a/ruby/lib/minitest/queue.rb +++ b/ruby/lib/minitest/queue.rb @@ -266,6 +266,11 @@ def run_from_queue(reporter, *) reopen_previous_step puts red("The heartbeat process died. This worker is exiting early.") exit!(41) + rescue StandardError => e + reopen_previous_step + puts red("This worker died because of a queue or framework error:") + puts red("#{e.class}: #{e.message}") + exit!(42) end end end diff --git a/ruby/test/fixtures/test/bad_framework_test.rb b/ruby/test/fixtures/test/bad_framework_test.rb new file mode 100644 index 00000000..02ddab20 --- /dev/null +++ b/ruby/test/fixtures/test/bad_framework_test.rb @@ -0,0 +1,14 @@ +# frozen_string_literal: true +require "test_helper" + +class Minitest::Queue::SingleExample + def run + raise StandardError, "Some error in the test framework" + end +end + +class BadFrameworkTest < Minitest::Test + def test_foo + assert false + end +end diff --git a/ruby/test/integration/minitest_redis_test.rb b/ruby/test/integration/minitest_redis_test.rb index b2abc02e..b488e993 100644 --- a/ruby/test/integration/minitest_redis_test.rb +++ b/ruby/test/integration/minitest_redis_test.rb @@ -933,6 +933,27 @@ def test_utf8_tests_and_marshal END end + def test_framework_error + capture_subprocess_io do + system( + { 'BUILDKITE' => '1' }, + @exe, 'run', + '--queue', @redis_url, + '--seed', 'foobar', + '--build', '1', + '--worker', '1', + '--timeout', '1', + '--max-requeues', '1', + '--requeue-tolerance', '1', + '-Itest', + 'test/bad_framework_test.rb', + chdir: 'test/fixtures/', + ) + end + + assert_equal 42, $?.exitstatus + end + private def normalize_xml(output) From e543a69fa7f5a954eb163e48b39676c699261af7 Mon Sep 17 00:00:00 2001 From: Zarif Mahfuz Date: Mon, 13 May 2024 08:22:53 -0600 Subject: [PATCH 2/2] Better error message for application error --- ruby/lib/minitest/queue.rb | 6 +++--- ruby/test/integration/minitest_redis_test.rb | 2 +- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/ruby/lib/minitest/queue.rb b/ruby/lib/minitest/queue.rb index c590b453..f87468d7 100644 --- a/ruby/lib/minitest/queue.rb +++ b/ruby/lib/minitest/queue.rb @@ -266,10 +266,10 @@ def run_from_queue(reporter, *) reopen_previous_step puts red("The heartbeat process died. This worker is exiting early.") exit!(41) - rescue StandardError => e + rescue => error reopen_previous_step - puts red("This worker died because of a queue or framework error:") - puts red("#{e.class}: #{e.message}") + puts red("This worker exited because of an uncaught application error:") + puts red("#{error.class}: #{error.message}") exit!(42) end end diff --git a/ruby/test/integration/minitest_redis_test.rb b/ruby/test/integration/minitest_redis_test.rb index b488e993..32268c4e 100644 --- a/ruby/test/integration/minitest_redis_test.rb +++ b/ruby/test/integration/minitest_redis_test.rb @@ -933,7 +933,7 @@ def test_utf8_tests_and_marshal END end - def test_framework_error + def test_application_error capture_subprocess_io do system( { 'BUILDKITE' => '1' },