1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

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.
This commit is contained in:
Jean Boussier 2022-06-07 10:51:28 +02:00
parent f075be3dcb
commit b1e6e58cd1
Notes: git 2022-06-07 20:20:05 +09:00

View file

@ -10,10 +10,10 @@ class TestThreadInstrumentation < Test::Unit::TestCase
Bug::ThreadInstrumentation::register_callback Bug::ThreadInstrumentation::register_callback
begin begin
threads = 5.times.map { Thread.new { sleep 0.5; 1 + 1; sleep 0.2 } } threaded_cpu_work
threads.each(&:join) counters = Bug::ThreadInstrumentation.counters
Bug::ThreadInstrumentation.counters.each do |c| counters.each do |c|
assert_predicate c,:nonzero? assert_predicate c,:nonzero?, "Call counters: #{counters.inspect}"
end end
ensure ensure
Bug::ThreadInstrumentation::unregister_callback Bug::ThreadInstrumentation::unregister_callback
@ -26,17 +26,26 @@ class TestThreadInstrumentation < Test::Unit::TestCase
require '-test-/thread/instrumentation' require '-test-/thread/instrumentation'
Bug::ThreadInstrumentation::register_callback Bug::ThreadInstrumentation::register_callback
read_pipe, write_pipe = IO.pipe
begin begin
pid = fork do pid = fork do
Bug::ThreadInstrumentation.reset_counters Bug::ThreadInstrumentation.reset_counters
threads = 5.times.map { Thread.new { sleep 0.5; 1 + 1; sleep 0.2 } } threaded_cpu_work
threads.each(&:join)
Bug::ThreadInstrumentation.counters.each do |c| write_pipe.write(Marshal.dump(Bug::ThreadInstrumentation.counters))
assert_predicate c,:nonzero? write_pipe.close
end exit!(0)
end end
write_pipe.close
_, status = Process.wait2(pid) _, status = Process.wait2(pid)
assert_predicate status, :success? 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 ensure
Bug::ThreadInstrumentation::unregister_callback Bug::ThreadInstrumentation::unregister_callback
end end
@ -46,5 +55,10 @@ class TestThreadInstrumentation < Test::Unit::TestCase
require '-test-/thread/instrumentation' require '-test-/thread/instrumentation'
assert Bug::ThreadInstrumentation::register_and_unregister_callbacks assert Bug::ThreadInstrumentation::register_and_unregister_callbacks
end end
end
private
def threaded_cpu_work
5.times.map { Thread.new { 100.times { |i| i + i } } }.each(&:join)
end
end