diff options
-rw-r--r-- | activesupport/lib/active_support/testing/parallelization.rb | 8 | ||||
-rw-r--r-- | railties/test/application/test_runner_test.rb | 18 |
2 files changed, 26 insertions, 0 deletions
diff --git a/activesupport/lib/active_support/testing/parallelization.rb b/activesupport/lib/active_support/testing/parallelization.rb index e760bf5ce3..f50a5e0554 100644 --- a/activesupport/lib/active_support/testing/parallelization.rb +++ b/activesupport/lib/active_support/testing/parallelization.rb @@ -27,6 +27,10 @@ module ActiveSupport @queue << o end + def length + @queue.length + end + def pop; @queue.pop; end end @@ -109,6 +113,10 @@ module ActiveSupport def shutdown @queue_size.times { @queue << nil } @pool.each { |pid| Process.waitpid pid } + + if @queue.length > 0 + raise "Queue not empty, but all workers have finished. This probably means that a worker crashed and #{@queue.length} tests were missed." + end end private diff --git a/railties/test/application/test_runner_test.rb b/railties/test/application/test_runner_test.rb index 1ab45abcd0..7fc918898b 100644 --- a/railties/test/application/test_runner_test.rb +++ b/railties/test/application/test_runner_test.rb @@ -564,6 +564,24 @@ module ApplicationTests assert_no_match "create_table(:users)", output end + def test_run_in_parallel_with_process_worker_crash + exercise_parallelization_regardless_of_machine_core_count(with: :processes) + + file_name = app_file("test/models/parallel_test.rb", <<-RUBY) + require 'test_helper' + + class ParallelTest < ActiveSupport::TestCase + def test_crash + Kernel.exit 1 + end + end + RUBY + + output = run_test_command(file_name) + + assert_match %r{Queue not empty, but all workers have finished. This probably means that a worker crashed and 1 tests were missed.}, output + end + def test_run_in_parallel_with_threads exercise_parallelization_regardless_of_machine_core_count(with: :threads) |