summaryrefslogtreecommitdiff
path: root/test/fiber
diff options
context:
space:
mode:
authorSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-09-14 11:10:02 +1200
committerSamuel Williams <samuel.williams@oriontransfer.co.nz>2020-09-14 16:44:09 +1200
commit8eea66a0ca8965ae8319b4c404f61c4d46866f64 (patch)
tree6083a6566df682ec5598bb971291cc150877de2b /test/fiber
parent0f613cc5f1bbe319ab916be905de263523ef5402 (diff)
Add support for Queue & SizedQueue.
Notes
Notes: Merged: https://github.com/ruby/ruby/pull/3434
Diffstat (limited to 'test/fiber')
-rw-r--r--test/fiber/test_mutex.rb31
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