diff options
| author | John Hawthorn <john@hawthorn.email> | 2023-12-03 18:13:25 -0800 |
|---|---|---|
| committer | John Hawthorn <john@hawthorn.email> | 2023-12-03 18:37:06 -0800 |
| commit | 85bc80a51be0ceedcc57e7b6b779e6f8f885859e (patch) | |
| tree | 6f868ca8df3b07da28a85bb35fb9e9599f7501b0 /test | |
| parent | 9c5e1b71891dab66544de2fe3311c45ede014fdd (diff) | |
Revert "Add missing GVL hooks for M:N threads and ractors"
This reverts commit ad54fbf281ca1935e79f4df1460b0106ba76761e.
Diffstat (limited to 'test')
| -rw-r--r-- | test/-ext-/thread/helper.rb | 51 | ||||
| -rw-r--r-- | test/-ext-/thread/test_instrumentation_api.rb | 84 |
2 files changed, 46 insertions, 89 deletions
diff --git a/test/-ext-/thread/helper.rb b/test/-ext-/thread/helper.rb deleted file mode 100644 index 3ea2057d15..0000000000 --- a/test/-ext-/thread/helper.rb +++ /dev/null @@ -1,51 +0,0 @@ -module ThreadInstrumentation - module TestHelper - private - - def record - Bug::ThreadInstrumentation.register_callback(!ENV["GVL_DEBUG"]) - yield - ensure - timeline = Bug::ThreadInstrumentation.unregister_callback - if $! - raise - else - return timeline - end - end - - def timeline_for(thread, timeline) - timeline.select { |t, _| t == thread }.map(&:last) - end - - def assert_consistent_timeline(events) - refute_predicate events, :empty? - - previous_event = nil - events.each do |event| - refute_equal :exited, previous_event, "`exited` must be the final event: #{events.inspect}" - case event - when :started - assert_nil previous_event, "`started` must be the first event: #{events.inspect}" - when :ready - unless previous_event.nil? - assert %i(started suspended).include?(previous_event), "`ready` must be preceded by `started` or `suspended`: #{events.inspect}" - end - when :resumed - unless previous_event.nil? - assert_equal :ready, previous_event, "`resumed` must be preceded by `ready`: #{events.inspect}" - end - when :suspended - unless previous_event.nil? - assert_equal :resumed, previous_event, "`suspended` must be preceded by `resumed`: #{events.inspect}" - end - when :exited - unless previous_event.nil? - assert %i(resumed suspended).include?(previous_event), "`exited` must be preceded by `resumed` or `suspended`: #{events.inspect}" - end - end - previous_event = event - end - end - end -end diff --git a/test/-ext-/thread/test_instrumentation_api.rb b/test/-ext-/thread/test_instrumentation_api.rb index 6ebdf3eac2..ef3b8358b3 100644 --- a/test/-ext-/thread/test_instrumentation_api.rb +++ b/test/-ext-/thread/test_instrumentation_api.rb @@ -1,10 +1,7 @@ # frozen_string_literal: false require 'envutil' -require_relative "helper" class TestThreadInstrumentation < Test::Unit::TestCase - include ThreadInstrumentation::TestHelper - def setup pend("No windows support") if /mswin|mingw|bccwin/ =~ RUBY_PLATFORM @@ -134,41 +131,6 @@ class TestThreadInstrumentation < Test::Unit::TestCase assert_equal %i(started ready resumed suspended ready resumed suspended exited), timeline end - def test_blocking_on_ractor - assert_ractor(<<-"RUBY", require_relative: "helper", require: "-test-/thread/instrumentation") - include ThreadInstrumentation::TestHelper - - full_timeline = record do - Ractor.new{ - Thread.current - }.take - end - - timeline = timeline_for(Thread.current, full_timeline) - assert_consistent_timeline(timeline) - assert_equal %i(suspended ready resumed), timeline - RUBY - end - - def test_sleeping_inside_ractor - assert_ractor(<<-"RUBY", require_relative: "helper", require: "-test-/thread/instrumentation") - include ThreadInstrumentation::TestHelper - - thread = nil - - full_timeline = record do - thread = Ractor.new{ - sleep 0.1 - Thread.current - }.take - end - - timeline = timeline_for(thread, full_timeline) - assert_consistent_timeline(timeline) - assert_equal %i(started ready resumed suspended ready resumed suspended exited), timeline - RUBY - end - def test_thread_blocked_forever_on_mutex mutex = Mutex.new mutex.lock @@ -243,6 +205,52 @@ class TestThreadInstrumentation < Test::Unit::TestCase private + def record + Bug::ThreadInstrumentation.register_callback(!ENV["GVL_DEBUG"]) + yield + ensure + timeline = Bug::ThreadInstrumentation.unregister_callback + if $! + raise + else + return timeline + end + end + + def assert_consistent_timeline(events) + refute_predicate events, :empty? + + previous_event = nil + events.each do |event| + refute_equal :exited, previous_event, "`exited` must be the final event: #{events.inspect}" + case event + when :started + assert_nil previous_event, "`started` must be the first event: #{events.inspect}" + when :ready + unless previous_event.nil? + assert %i(started suspended).include?(previous_event), "`ready` must be preceded by `started` or `suspended`: #{events.inspect}" + end + when :resumed + unless previous_event.nil? + assert_equal :ready, previous_event, "`resumed` must be preceded by `ready`: #{events.inspect}" + end + when :suspended + unless previous_event.nil? + assert_equal :resumed, previous_event, "`suspended` must be preceded by `resumed`: #{events.inspect}" + end + when :exited + unless previous_event.nil? + assert %i(resumed suspended).include?(previous_event), "`exited` must be preceded by `resumed` or `suspended`: #{events.inspect}" + end + end + previous_event = event + end + end + + def timeline_for(thread, timeline) + timeline.select { |t, _| t == thread }.map(&:last) + end + def fib(n = 30) return n if n <= 1 fib(n-1) + fib(n-2) |
