Debug TestThreadInstrumentation
It previously failed with: ``` 1) Failure: TestThreadInstrumentation#test_thread_instrumentation_fork_safe [/home/runner/work/ruby/ruby/src/test/-ext-/thread/test_instrumentation_api.rb:50]: <5> expected but was <4>. ``` Suggesting one `EXIT` event wasn't fired or processed. Adding an assetion on `Thead#status` may help figure out what is wrong.
This commit is contained in:
parent
78425d7e74
commit
c34a5469c8
Notes:
git
2022-06-17 22:11:42 +09:00
@ -4,17 +4,23 @@ class TestThreadInstrumentation < Test::Unit::TestCase
|
|||||||
pend("TODO: No windows support yet") if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
|
pend("TODO: No windows support yet") if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
|
||||||
end
|
end
|
||||||
|
|
||||||
|
THREADS_COUNT = 3
|
||||||
|
|
||||||
def test_thread_instrumentation
|
def test_thread_instrumentation
|
||||||
require '-test-/thread/instrumentation'
|
require '-test-/thread/instrumentation'
|
||||||
Bug::ThreadInstrumentation.reset_counters
|
Bug::ThreadInstrumentation.reset_counters
|
||||||
Bug::ThreadInstrumentation::register_callback
|
Bug::ThreadInstrumentation::register_callback
|
||||||
|
|
||||||
begin
|
begin
|
||||||
threaded_cpu_work
|
threads = threaded_cpu_work
|
||||||
|
assert_equal [false] * THREADS_COUNT, threads.map(&:status)
|
||||||
counters = Bug::ThreadInstrumentation.counters
|
counters = Bug::ThreadInstrumentation.counters
|
||||||
counters.each do |c|
|
counters.each do |c|
|
||||||
assert_predicate c,:nonzero?, "Call counters: #{counters.inspect}"
|
assert_predicate c,:nonzero?, "Call counters: #{counters.inspect}"
|
||||||
end
|
end
|
||||||
|
|
||||||
|
sleep 0.01 # Give more time to the native threads to execute their EXIT hook
|
||||||
|
assert_equal counters.first, counters.last # exited as many times as we entered
|
||||||
ensure
|
ensure
|
||||||
Bug::ThreadInstrumentation::unregister_callback
|
Bug::ThreadInstrumentation::unregister_callback
|
||||||
end
|
end
|
||||||
@ -31,8 +37,9 @@ class TestThreadInstrumentation < Test::Unit::TestCase
|
|||||||
begin
|
begin
|
||||||
pid = fork do
|
pid = fork do
|
||||||
Bug::ThreadInstrumentation.reset_counters
|
Bug::ThreadInstrumentation.reset_counters
|
||||||
threaded_cpu_work
|
threads = threaded_cpu_work
|
||||||
|
write_pipe.write(Marshal.dump(threads.map(&:status)))
|
||||||
|
sleep 0.01 # Give more time to the native threads to execute their EXIT hook
|
||||||
write_pipe.write(Marshal.dump(Bug::ThreadInstrumentation.counters))
|
write_pipe.write(Marshal.dump(Bug::ThreadInstrumentation.counters))
|
||||||
write_pipe.close
|
write_pipe.close
|
||||||
exit!(0)
|
exit!(0)
|
||||||
@ -41,6 +48,9 @@ class TestThreadInstrumentation < Test::Unit::TestCase
|
|||||||
_, status = Process.wait2(pid)
|
_, status = Process.wait2(pid)
|
||||||
assert_predicate status, :success?
|
assert_predicate status, :success?
|
||||||
|
|
||||||
|
thread_statuses = Marshal.load(read_pipe)
|
||||||
|
assert_equal [false] * THREADS_COUNT, thread_statuses
|
||||||
|
|
||||||
counters = Marshal.load(read_pipe)
|
counters = Marshal.load(read_pipe)
|
||||||
read_pipe.close
|
read_pipe.close
|
||||||
counters.each do |c|
|
counters.each do |c|
|
||||||
@ -61,6 +71,6 @@ class TestThreadInstrumentation < Test::Unit::TestCase
|
|||||||
private
|
private
|
||||||
|
|
||||||
def threaded_cpu_work
|
def threaded_cpu_work
|
||||||
5.times.map { Thread.new { 100.times { |i| i + i } } }.each(&:join)
|
THREADS_COUNT.times.map { Thread.new { 100.times { |i| i + i } } }.each(&:join)
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user