diff options
Diffstat (limited to 'test/ruby/test_thread.rb')
| -rw-r--r-- | test/ruby/test_thread.rb | 101 |
1 files changed, 12 insertions, 89 deletions
diff --git a/test/ruby/test_thread.rb b/test/ruby/test_thread.rb index 703373b11e..41cee124be 100644 --- a/test/ruby/test_thread.rb +++ b/test/ruby/test_thread.rb @@ -29,19 +29,13 @@ class TestThread < Test::Unit::TestCase end def test_inspect - m = Thread::Mutex.new - m.lock line = __LINE__+1 - th = Module.new {break module_eval("class C\u{30b9 30ec 30c3 30c9} < Thread; self; end")}.start do - m.synchronize {} - end - Thread.pass until th.stop? + th = Module.new {break module_eval("class C\u{30b9 30ec 30c3 30c9} < Thread; self; end")}.start{} s = th.inspect assert_include(s, "::C\u{30b9 30ec 30c3 30c9}:") assert_include(s, " #{__FILE__}:#{line} ") assert_equal(s, th.to_s) ensure - m.unlock th.join end @@ -323,7 +317,7 @@ class TestThread < Test::Unit::TestCase s += 1 end Thread.pass until t.stop? - sleep 1 if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? # t.stop? behaves unexpectedly with --jit-wait + sleep 1 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? # t.stop? behaves unexpectedly with --jit-wait assert_equal(1, s) t.wakeup Thread.pass while t.alive? @@ -395,7 +389,7 @@ class TestThread < Test::Unit::TestCase end INPUT - assert_in_out_err(%w(-d), <<-INPUT, %w(false 2), %r".+") + assert_in_out_err(%w(--disable-gems -d), <<-INPUT, %w(false 2), %r".+") p Thread.abort_on_exception begin t = Thread.new { raise } @@ -506,7 +500,7 @@ class TestThread < Test::Unit::TestCase def test_ignore_deadlock if /mswin|mingw/ =~ RUBY_PLATFORM - omit "can't trap a signal from another process on Windows" + skip "can't trap a signal from another process on Windows" end assert_in_out_err([], <<-INPUT, %w(false :sig), [], :signal=>:INT, timeout: 1, timeout_error: nil) p Thread.ignore_deadlock @@ -737,7 +731,7 @@ class TestThread < Test::Unit::TestCase end def test_no_valid_cfp - omit 'with win32ole, cannot run this testcase because win32ole redefines Thread#initialize' if defined?(WIN32OLE) + skip 'with win32ole, cannot run this testcase because win32ole redefines Thread#initialize' if defined?(WIN32OLE) bug5083 = '[ruby-dev:44208]' assert_equal([], Thread.new(&Module.method(:nesting)).value, bug5083) assert_instance_of(Thread, Thread.new(:to_s, &Class.new.method(:undef_method)).join, bug5083) @@ -972,8 +966,6 @@ _eom end def test_thread_timer_and_interrupt - omit "[Bug #18613]" if /freebsd/ =~ RUBY_PLATFORM - bug5757 = '[ruby-dev:44985]' pid = nil cmd = 'Signal.trap(:INT, "DEFAULT"); pipe=IO.pipe; Thread.start {Thread.pass until Thread.main.stop?; puts; STDOUT.flush}; pipe[0].read' @@ -1076,7 +1068,7 @@ q.pop puts mth.status Process.kill(:INT, $$) } - sleep + sleep 0.1 INPUT end @@ -1263,7 +1255,6 @@ q.pop assert_predicate(status, :success?, bug18902) ensure th.kill - th.join end end if Process.respond_to?(:fork) @@ -1279,7 +1270,7 @@ q.pop end if Process.respond_to?(:fork) def test_fork_while_parent_locked - omit 'needs fork' unless Process.respond_to?(:fork) + skip 'needs fork' unless Process.respond_to?(:fork) m = Thread::Mutex.new nr = 1 thrs = [] @@ -1300,7 +1291,7 @@ q.pop end def test_fork_while_mutex_locked_by_forker - omit 'needs fork' unless Process.respond_to?(:fork) + skip 'needs fork' unless Process.respond_to?(:fork) m = Thread::Mutex.new m.synchronize do pid = fork do @@ -1361,61 +1352,6 @@ q.pop t.join end - def test_yield_across_thread_through_enum - bug18649 = '[ruby-core:107980] [Bug #18649]' - @log = [] - - def self.p(arg) - @log << arg - end - - def self.synchronize - yield - end - - def self.execute(task) - success = true - value = reason = nil - end_sync = false - - synchronize do - begin - p :before - value = task.call - p :never_reached - success = true - rescue StandardError => ex - ex = ex.class - p [:rescue, ex] - reason = ex - success = false - end - - end_sync = true - p :end_sync - end - - p :should_not_reach_here! unless end_sync - [success, value, reason] - end - - def self.foo - Thread.new do - result = execute(-> { yield 42 }) - p [:result, result] - end.join - end - - value = to_enum(:foo).first - expected = [:before, - [:rescue, LocalJumpError], - :end_sync, - [:result, [false, nil, LocalJumpError]]] - - assert_equal(expected, @log, bug18649) - assert_equal(42, value, bug18649) - end - def test_thread_setname_in_initialize bug12290 = '[ruby-core:74963] [Bug #12290]' c = Class.new(Thread) {def initialize() self.name = "foo"; super; end} @@ -1423,7 +1359,7 @@ q.pop end def test_thread_native_thread_id - omit "don't support native_thread_id" unless Thread.method_defined?(:native_thread_id) + skip "don't support native_thread_id" unless Thread.method_defined?(:native_thread_id) assert_instance_of Integer, Thread.main.native_thread_id th1 = Thread.start{sleep} @@ -1446,8 +1382,8 @@ q.pop def test_thread_interrupt_for_killed_thread opts = { timeout: 5, timeout_error: nil } - # prevent SIGABRT from slow shutdown with RJIT - opts[:reprieve] = 3 if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled? + # prevent SIGABRT from slow shutdown with MJIT + opts[:reprieve] = 3 if defined?(RubyVM::MJIT) && RubyVM::MJIT.enabled? assert_normal_exit(<<-_end, '[Bug #8996]', **opts) Thread.report_on_exception = false @@ -1462,14 +1398,9 @@ q.pop def test_signal_at_join if /mswin|mingw/ =~ RUBY_PLATFORM - omit "can't trap a signal from another process on Windows" + skip "can't trap a signal from another process on Windows" # opt = {new_pgroup: true} end - - if /freebsd/ =~ RUBY_PLATFORM - omit "[Bug #18613]" - end - assert_separately([], "#{<<~"{#"}\n#{<<~'};'}", timeout: 120) {# n = 1000 @@ -1516,12 +1447,4 @@ q.pop end }; end - - def test_pending_interrupt? - t = Thread.handle_interrupt(Exception => :never) { Thread.new { Thread.stop } } - t.raise(StandardError) - assert_equal(true, t.pending_interrupt?) - assert_equal(true, t.pending_interrupt?(Exception)) - assert_equal(false, t.pending_interrupt?(ArgumentError)) - end end |
