diff options
Diffstat (limited to 'test/monitor/test_monitor.rb')
-rw-r--r-- | test/monitor/test_monitor.rb | 33 |
1 files changed, 21 insertions, 12 deletions
diff --git a/test/monitor/test_monitor.rb b/test/monitor/test_monitor.rb index 734b639d4c..4c55afca6c 100644 --- a/test/monitor/test_monitor.rb +++ b/test/monitor/test_monitor.rb @@ -10,9 +10,16 @@ class TestMonitor < Test::Unit::TestCase @monitor = Monitor.new end + def test_enter_in_different_fibers + @monitor.enter + Fiber.new { + assert_equal false, @monitor.try_enter + }.resume + end + def test_enter ary = [] - queue = Queue.new + queue = Thread::Queue.new th = Thread.start { queue.pop @monitor.enter @@ -76,7 +83,7 @@ class TestMonitor < Test::Unit::TestCase def test_synchronize ary = [] - queue = Queue.new + queue = Thread::Queue.new th = Thread.start { queue.pop @monitor.synchronize do @@ -101,7 +108,7 @@ class TestMonitor < Test::Unit::TestCase def test_killed_thread_in_synchronize ary = [] - queue = Queue.new + queue = Thread::Queue.new t1 = Thread.start { queue.pop @monitor.synchronize { @@ -129,8 +136,8 @@ class TestMonitor < Test::Unit::TestCase end def test_try_enter - queue1 = Queue.new - queue2 = Queue.new + queue1 = Thread::Queue.new + queue2 = Thread::Queue.new th = Thread.start { queue1.deq @monitor.enter @@ -169,8 +176,8 @@ class TestMonitor < Test::Unit::TestCase end def test_mon_locked_and_owned - queue1 = Queue.new - queue2 = Queue.new + queue1 = Thread::Queue.new + queue2 = Thread::Queue.new th = Thread.start { @monitor.enter queue1.enq(nil) @@ -203,7 +210,7 @@ class TestMonitor < Test::Unit::TestCase cond = @monitor.new_cond a = "foo" - queue1 = Queue.new + queue1 = Thread::Queue.new th = Thread.start do queue1.deq @monitor.synchronize do @@ -255,7 +262,7 @@ class TestMonitor < Test::Unit::TestCase def test_timedwait cond = @monitor.new_cond b = "foo" - queue2 = Queue.new + queue2 = Thread::Queue.new th = Thread.start do queue2.deq @monitor.synchronize do @@ -275,7 +282,7 @@ class TestMonitor < Test::Unit::TestCase assert_join_threads([th, th2]) c = "foo" - queue3 = Queue.new + queue3 = Thread::Queue.new th = Thread.start do queue3.deq @monitor.synchronize do @@ -287,12 +294,14 @@ class TestMonitor < Test::Unit::TestCase @monitor.synchronize do assert_equal("foo", c) result3 = cond.wait(0.1) - assert_equal(true, result3) # wait always returns true in Ruby 1.9 + assert_equal(false, result3) assert_equal("foo", c) queue3.enq(nil) result4 = cond.wait assert_equal(true, result4) assert_equal("bar", c) + ensure + queue3.enq(nil) end end assert_join_threads([th, th2]) @@ -305,7 +314,7 @@ class TestMonitor < Test::Unit::TestCase # end # end # } -# queue3 = Queue.new +# queue3 = Thread::Queue.new # Thread.start do # queue3.pop # @monitor.synchronize do |