aboutsummaryrefslogtreecommitdiffstats
path: root/test/ruby/test_thread_queue.rb
diff options
context:
space:
mode:
authorJean Boussier <jean.boussier@gmail.com>2022-07-26 17:40:00 +0200
committerJean Boussier <jean.boussier@gmail.com>2022-08-18 10:07:37 +0200
commitfe61cad7490da8a879597f851f4a89856d44838e (patch)
tree29844ee84fe8b5c547ab8c58b8464ab450be0873 /test/ruby/test_thread_queue.rb
parentb3718edee28d5155ebc383d17ab58867e20f4aa2 (diff)
downloadruby-fe61cad7490da8a879597f851f4a89856d44838e.tar.gz
Implement SizedQueue#push(timeout: sec)
[Feature #18944] If both `non_block=true` and `timeout:` are supplied, ArgumentError is raised.
Diffstat (limited to 'test/ruby/test_thread_queue.rb')
-rw-r--r--test/ruby/test_thread_queue.rb18
1 files changed, 18 insertions, 0 deletions
diff --git a/test/ruby/test_thread_queue.rb b/test/ruby/test_thread_queue.rb
index 1c852474b4..bd5728389d 100644
--- a/test/ruby/test_thread_queue.rb
+++ b/test/ruby/test_thread_queue.rb
@@ -168,6 +168,24 @@ class TestThreadQueue < Test::Unit::TestCase
end
end
+ def test_sized_queue_push_timeout
+ q = Thread::SizedQueue.new(1)
+
+ q << 1
+ assert_equal 1, q.size
+
+ t1 = Thread.new { q.push(2, timeout: 1) }
+ assert_equal t1, t1.join(2)
+ assert_nil t1.value
+
+ t2 = Thread.new { q.push(2, timeout: 0.1) }
+ assert_equal t2, t2.join(0.2)
+ assert_nil t2.value
+ ensure
+ t1&.kill
+ t2&.kill
+ end
+
def test_sized_queue_push_interrupt
q = Thread::SizedQueue.new(1)
q.push(1)