diff options
author | Jean Boussier <[email protected]> | 2022-10-06 15:53:16 +0200 |
---|---|---|
committer | Jean Boussier <[email protected]> | 2022-10-17 16:56:00 +0200 |
commit | 60defe0a68a40d1b3225cf6b971ea195e19ae2e2 (patch) | |
tree | 65072a9531c7eb9abfa887a1ad0c18bd4242502d /spec/ruby/shared/sizedqueue | |
parent | 7db29de008bbf06ce1dc2a1e9fd9c9684b31e325 (diff) |
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.
Notes
Notes:
Merged: https://github.com/ruby/ruby/pull/6500
Diffstat (limited to 'spec/ruby/shared/sizedqueue')
-rw-r--r-- | spec/ruby/shared/sizedqueue/enque.rb | 8 |
1 files changed, 7 insertions, 1 deletions
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 { |