diff options
author | Jean Boussier <jean.boussier@gmail.com> | 2022-10-06 15:53:16 +0200 |
---|---|---|
committer | Jean Boussier <jean.boussier@gmail.com> | 2022-10-17 16:56:00 +0200 |
commit | 60defe0a68a40d1b3225cf6b971ea195e19ae2e2 (patch) | |
tree | 65072a9531c7eb9abfa887a1ad0c18bd4242502d /spec/ruby/shared | |
parent | 7db29de008bbf06ce1dc2a1e9fd9c9684b31e325 (diff) | |
download | ruby-60defe0a68a40d1b3225cf6b971ea195e19ae2e2.tar.gz |
thread_sync.c: Clarify and document the behavior of timeout == 0
[Feature #18982]
Instead of introducing an `exception: false` argument to have `non_block`
return nil rather than raise, we can clearly document that a timeout of 0
immediately returns.
The code is refactored a bit to avoid doing a time calculation in
such case.
Diffstat (limited to 'spec/ruby/shared')
-rw-r--r-- | spec/ruby/shared/queue/deque.rb | 7 | ||||
-rw-r--r-- | spec/ruby/shared/sizedqueue/enque.rb | 8 |
2 files changed, 14 insertions, 1 deletions
diff --git a/spec/ruby/shared/queue/deque.rb b/spec/ruby/shared/queue/deque.rb index ed32bd29c8..616e56ec8a 100644 --- a/spec/ruby/shared/queue/deque.rb +++ b/spec/ruby/shared/queue/deque.rb @@ -87,6 +87,13 @@ describe :queue_deq, shared: true do t.join end + it "immediately returns nil if no item is available and the timeout is 0" do + q = @object.call + q << 1 + q.send(@method, timeout: 0).should == 1 + q.send(@method, timeout: 0).should == nil + end + it "raise TypeError if timeout is not a valid numeric" do q = @object.call -> { q.send(@method, timeout: "1") }.should raise_error( diff --git a/spec/ruby/shared/sizedqueue/enque.rb b/spec/ruby/shared/sizedqueue/enque.rb index 126470594a..059f1025a7 100644 --- a/spec/ruby/shared/sizedqueue/enque.rb +++ b/spec/ruby/shared/sizedqueue/enque.rb @@ -73,7 +73,13 @@ describe :sizedqueue_enq, shared: true do t.join end - it "returns nil if no item is available in time" do + it "returns nil if no space is avialable and timeout is 0" do + q = @object.call(1) + q.send(@method, 1, timeout: 0).should == q + q.send(@method, 2, timeout: 0).should == nil + end + + it "returns nil if no space is available in time" do q = @object.call(1) q << 1 t = Thread.new { |