summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2022-06-17 10:09:02 +0200
committerJean Boussier <jean.boussier@gmail.com>2022-06-17 15:11:10 +0200
commitc34a5469c8d53029a5f3cdde0ca855e47a92c7d7 (patch)
tree4b8c735eb5e4fd842824cb034459a607442fb982
parent78425d7e74887b57ee15e6b8933bd3878db6a888 (diff)
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.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/6032
-rw-r--r--test/-ext-/thread/test_instrumentation_api.rb18
1 files changed, 14 insertions, 4 deletions
diff --git a/test/-ext-/thread/test_instrumentation_api.rb b/test/-ext-/thread/test_instrumentation_api.rb
index ff76e95bcd..adfb6443bc 100644
--- a/test/-ext-/thread/test_instrumentation_api.rb
+++ b/test/-ext-/thread/test_instrumentation_api.rb
@@ -4,17 +4,23 @@ class TestThreadInstrumentation < Test::Unit::TestCase
pend("TODO: No windows support yet") if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM
end
+ THREADS_COUNT = 3
+
def test_thread_instrumentation
require '-test-/thread/instrumentation'
Bug::ThreadInstrumentation.reset_counters
Bug::ThreadInstrumentation::register_callback
begin
- threaded_cpu_work
+ threads = threaded_cpu_work
+ assert_equal [false] * THREADS_COUNT, threads.map(&:status)
counters = Bug::ThreadInstrumentation.counters
counters.each do |c|
assert_predicate c,:nonzero?, "Call counters: #{counters.inspect}"
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
Bug::ThreadInstrumentation::unregister_callback
end
@@ -31,8 +37,9 @@ class TestThreadInstrumentation < Test::Unit::TestCase
begin
pid = fork do
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.close
exit!(0)
@@ -41,6 +48,9 @@ class TestThreadInstrumentation < Test::Unit::TestCase
_, status = Process.wait2(pid)
assert_predicate status, :success?
+ thread_statuses = Marshal.load(read_pipe)
+ assert_equal [false] * THREADS_COUNT, thread_statuses
+
counters = Marshal.load(read_pipe)
read_pipe.close
counters.each do |c|
@@ -61,6 +71,6 @@ class TestThreadInstrumentation < Test::Unit::TestCase
private
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