diff options
author | Jean Boussier <[email protected]> | 2022-07-26 17:40:00 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2022-08-02 11:04:28 +0200 |
commit | e3aabe93aae87a60ba7b8f1a0fd590534647e352 (patch) | |
tree | 3f5c15b61c9914c7e1a34ad56d042dcf70024f75 /test/ruby/test_thread_queue.rb | |
parent | ec3f59309e3f08339c4c76a6881901580801d6cd (diff) |
Implement Queue#pop(timeout: sec)
[Feature #18774]
As well as `SizedQueue#pop(timeout: sec)`
If both `non_block=true` and `timeout:` are supplied, ArgumentError
is raised.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6185
Diffstat (limited to 'test/ruby/test_thread_queue.rb')
-rw-r--r-- | test/ruby/test_thread_queue.rb | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/test/ruby/test_thread_queue.rb b/test/ruby/test_thread_queue.rb index ebf7ded3b9..aa4ea0a400 100644 --- a/test/ruby/test_thread_queue.rb +++ b/test/ruby/test_thread_queue.rb @@ -111,6 +111,23 @@ class TestThreadQueue < Test::Unit::TestCase assert_equal(0, q.num_waiting) end + def test_queue_pop_timeout + q = Thread::Queue.new + q << 1 + assert_equal 1, q.pop(timeout: 1) + + t1 = Thread.new { q.pop(timeout: 1) } + assert_equal t1, t1.join(2) + assert_nil t1.value + + t2 = Thread.new { q.pop(timeout: 0.1) } + assert_equal t2, t2.join(0.2) + assert_nil t2.value + ensure + t1&.kill + t2&.kill + end + def test_queue_pop_non_block q = Thread::Queue.new assert_raise_with_message(ThreadError, /empty/) do @@ -126,6 +143,24 @@ class TestThreadQueue < Test::Unit::TestCase assert_equal(0, q.num_waiting) end + def test_sized_queue_pop_timeout + q = Thread::SizedQueue.new(1) + + q << 1 + assert_equal 1, q.pop(timeout: 1) + + t1 = Thread.new { q.pop(timeout: 1) } + assert_equal t1, t1.join(2) + assert_nil t1.value + + t2 = Thread.new { q.pop(timeout: 0.1) } + assert_equal t2, t2.join(0.2) + assert_nil t2.value + ensure + t1&.kill + t2&.kill + end + def test_sized_queue_pop_non_block q = Thread::SizedQueue.new(1) assert_raise_with_message(ThreadError, /empty/) do |