diff options
Diffstat (limited to 'test/fiber/test_mutex.rb')
-rw-r--r-- | test/fiber/test_mutex.rb | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb index 0842427760..2cee2cc235 100644 --- a/test/fiber/test_mutex.rb +++ b/test/fiber/test_mutex.rb @@ -4,7 +4,7 @@ require_relative 'scheduler' class TestFiberMutex < Test::Unit::TestCase def test_mutex_synchronize - mutex = Mutex.new + mutex = Thread::Mutex.new thread = Thread.new do scheduler = Scheduler.new @@ -23,7 +23,7 @@ class TestFiberMutex < Test::Unit::TestCase end def test_mutex_interleaved_locking - mutex = Mutex.new + mutex = Thread::Mutex.new thread = Thread.new do scheduler = Scheduler.new @@ -48,7 +48,7 @@ class TestFiberMutex < Test::Unit::TestCase end def test_mutex_thread - mutex = Mutex.new + mutex = Thread::Mutex.new mutex.lock thread = Thread.new do @@ -71,7 +71,7 @@ class TestFiberMutex < Test::Unit::TestCase end def test_mutex_fiber_raise - mutex = Mutex.new + mutex = Thread::Mutex.new ran = false main = Thread.new do @@ -103,8 +103,8 @@ class TestFiberMutex < Test::Unit::TestCase end def test_condition_variable - mutex = Mutex.new - condition = ConditionVariable.new + mutex = Thread::Mutex.new + condition = Thread::ConditionVariable.new signalled = 0 @@ -138,7 +138,7 @@ class TestFiberMutex < Test::Unit::TestCase end def test_queue - queue = Queue.new + queue = Thread::Queue.new processed = 0 thread = Thread.new do @@ -169,7 +169,7 @@ class TestFiberMutex < Test::Unit::TestCase end def test_queue_pop_waits - queue = Queue.new + queue = Thread::Queue.new running = false thread = Thread.new do @@ -194,11 +194,11 @@ class TestFiberMutex < Test::Unit::TestCase end def test_mutex_deadlock - error_pattern = /No live threads left. Deadlock\?/ + error_pattern = /lock already owned by another fiber/ assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], error_pattern, success: false require 'scheduler' - mutex = Mutex.new + mutex = Thread::Mutex.new thread = Thread.new do scheduler = Scheduler.new @@ -207,7 +207,7 @@ class TestFiberMutex < Test::Unit::TestCase Fiber.schedule do mutex.synchronize do puts 'in synchronize' - Fiber.yield + scheduler.transfer end end @@ -217,4 +217,24 @@ class TestFiberMutex < Test::Unit::TestCase thread.join RUBY end + + def test_mutex_fiber_deadlock_no_scheduler + thr = Thread.new do + loop do + sleep 1 + end + end + + mutex = Mutex.new + mutex.synchronize do + error = assert_raise ThreadError do + Fiber.new do + mutex.lock + end.resume + end + assert_includes error.message, "deadlock; lock already owned by another fiber belonging to the same thread" + end + ensure + thr&.kill&.join + end end |