ruby-changes:72085
From: Jean <ko1@a...>
Date: Tue, 7 Jun 2022 20:20:07 +0900 (JST)
Subject: [ruby-changes:72085] b1e6e58cd1 (master): Refactor TestThreadInstrumentation to investigate CI flakiness
https://git.ruby-lang.org/ruby.git/commit/?id=b1e6e58cd1 From b1e6e58cd1393bf85ae14b82fe2f944192dc336e Mon Sep 17 00:00:00 2001 From: Jean Boussier <jean.boussier@g...> Date: Tue, 7 Jun 2022 10:51:28 +0200 Subject: Refactor TestThreadInstrumentation to investigate CI flakiness `test_thread_instrumentation_fork_safe` has been failing occasionaly on Ubuntu and Arch. At this stage we're not sure why, all we know is that the child exit with status 1. I suspect that something entirely unrelated cause the forked children to fail on exit, so by using `exit!(0)` and doing assertions in the parent I hope to be resilient to that. --- test/-ext-/thread/test_instrumentation_api.rb | 34 +++++++++++++++++++-------- 1 file changed, 24 insertions(+), 10 deletions(-) diff --git a/test/-ext-/thread/test_instrumentation_api.rb b/test/-ext-/thread/test_instrumentation_api.rb index 08bcda7ed9..d110348d73 100644 --- a/test/-ext-/thread/test_instrumentation_api.rb +++ b/test/-ext-/thread/test_instrumentation_api.rb @@ -10,10 +10,10 @@ class TestThreadInstrumentation < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/thread/test_instrumentation_api.rb#L10 Bug::ThreadInstrumentation::register_callback begin - threads = 5.times.map { Thread.new { sleep 0.5; 1 + 1; sleep 0.2 } } - threads.each(&:join) - Bug::ThreadInstrumentation.counters.each do |c| - assert_predicate c,:nonzero? + threaded_cpu_work + counters = Bug::ThreadInstrumentation.counters + counters.each do |c| + assert_predicate c,:nonzero?, "Call counters: #{counters.inspect}" end ensure Bug::ThreadInstrumentation::unregister_callback @@ -26,17 +26,26 @@ class TestThreadInstrumentation < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/thread/test_instrumentation_api.rb#L26 require '-test-/thread/instrumentation' Bug::ThreadInstrumentation::register_callback + read_pipe, write_pipe = IO.pipe + begin pid = fork do Bug::ThreadInstrumentation.reset_counters - threads = 5.times.map { Thread.new { sleep 0.5; 1 + 1; sleep 0.2 } } - threads.each(&:join) - Bug::ThreadInstrumentation.counters.each do |c| - assert_predicate c,:nonzero? - end + threaded_cpu_work + + write_pipe.write(Marshal.dump(Bug::ThreadInstrumentation.counters)) + write_pipe.close + exit!(0) end + write_pipe.close _, status = Process.wait2(pid) assert_predicate status, :success? + + counters = Marshal.load(read_pipe) + read_pipe.close + counters.each do |c| + assert_predicate c,:nonzero?, "Call counters: #{counters.inspect}" + end ensure Bug::ThreadInstrumentation::unregister_callback end @@ -46,5 +55,10 @@ class TestThreadInstrumentation < Test::Unit::TestCase https://github.com/ruby/ruby/blob/trunk/test/-ext-/thread/test_instrumentation_api.rb#L55 require '-test-/thread/instrumentation' assert Bug::ThreadInstrumentation::register_and_unregister_callbacks end -end + private + + def threaded_cpu_work + 5.times.map { Thread.new { 100.times { |i| i + i } } }.each(&:join) + end +end -- cgit v1.2.1 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/