diff --git a/ruby/test/minitest/queue/order_reporter_test.rb b/ruby/test/minitest/queue/order_reporter_test.rb index 3ba2952d..ad29d58c 100644 --- a/ruby/test/minitest/queue/order_reporter_test.rb +++ b/ruby/test/minitest/queue/order_reporter_test.rb @@ -25,18 +25,16 @@ def test_before_test unless truffleruby? def test_forking - pid = fork do - @reporter.start - end + # `start` truncates the log. In production it runs in the parent before + # workers fork; wait for it here so the truncate can't race the appends. + Process.waitpid(fork { @reporter.start }) pids = 5.times.map do fork do @reporter.before_test(runnable(Process.pid)) @reporter.report end end - (pids + [pid]).map do |pid| - Process.waitpid(pid) - end + pids.each { |pid| Process.waitpid(pid) } assert_equal pids.map { |pid| "Minitest::Test##{pid}" }.sort, File.readlines(log_path).map(&:chomp).sort end @@ -44,10 +42,6 @@ def test_forking private - def delete_log - File.delete(log_path) if File.exists?(log_path) - end - def log_path @path ||= File.join(Dir.tmpdir, 'test_order.log') end