diff options
author | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-09-14 11:10:02 +1200 |
---|---|---|
committer | Samuel Williams <samuel.williams@oriontransfer.co.nz> | 2020-09-14 16:44:09 +1200 |
commit | 8eea66a0ca8965ae8319b4c404f61c4d46866f64 (patch) | |
tree | 6083a6566df682ec5598bb971291cc150877de2b /test/fiber/test_mutex.rb | |
parent | 0f613cc5f1bbe319ab916be905de263523ef5402 (diff) | |
download | ruby-8eea66a0ca8965ae8319b4c404f61c4d46866f64.tar.gz |
Add support for Queue & SizedQueue.
Diffstat (limited to 'test/fiber/test_mutex.rb')
-rw-r--r-- | test/fiber/test_mutex.rb | 31 |
1 files changed, 31 insertions, 0 deletions
diff --git a/test/fiber/test_mutex.rb b/test/fiber/test_mutex.rb index 21034128a1..1f53ae1a1f 100644 --- a/test/fiber/test_mutex.rb +++ b/test/fiber/test_mutex.rb @@ -84,6 +84,37 @@ class TestFiberMutex < Test::Unit::TestCase assert signalled > 1 end + def test_queue + queue = Queue.new + processed = 0 + + thread = Thread.new do + scheduler = Scheduler.new + Thread.current.scheduler = scheduler + + Fiber.schedule do + 3.times do |i| + queue << i + sleep 0.1 + end + + queue.close + end + + Fiber.schedule do + while item = queue.pop + processed += 1 + end + end + + scheduler.run + end + + thread.join + + assert processed == 3 + end + def test_mutex_deadlock err = /No live threads left. Deadlock\?/ assert_in_out_err %W[-I#{__dir__} -], <<-RUBY, ['in synchronize'], err, success: false |