summaryrefslogtreecommitdiff
path: root/spec/ruby/library/conditionvariable
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-06 15:42:01 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-06 15:42:36 +0900
commit739fdb7ff0767ae4a666ca83f61e807c0c6c7115 (patch)
tree5f5e7da99c0ac3185e2b6d5baa6ae32696376d05 /spec/ruby/library/conditionvariable
parent32adae431d3f58e4103ca7ea507ee110c18e19c4 (diff)
[ruby/spec] Don't care about return values
RDoc says nothing about them. Added an example that ConditionVariable#wait can be woken up by ConditionVariable#signal, instead.
Diffstat (limited to 'spec/ruby/library/conditionvariable')
-rw-r--r--spec/ruby/library/conditionvariable/broadcast_spec.rb27
-rw-r--r--spec/ruby/library/conditionvariable/signal_spec.rb27
-rw-r--r--spec/ruby/library/conditionvariable/wait_spec.rb7
3 files changed, 4 insertions, 57 deletions
diff --git a/spec/ruby/library/conditionvariable/broadcast_spec.rb b/spec/ruby/library/conditionvariable/broadcast_spec.rb
index 1dccdf4895..d88159df23 100644
--- a/spec/ruby/library/conditionvariable/broadcast_spec.rb
+++ b/spec/ruby/library/conditionvariable/broadcast_spec.rb
@@ -2,33 +2,6 @@ require_relative '../../spec_helper'
require 'thread'
describe "ConditionVariable#broadcast" do
- it "returns self if nothing to broadcast to" do
- cv = ConditionVariable.new
- cv.broadcast.should == cv
- end
-
- it "returns self if something is waiting for a broadcast" do
- m = Mutex.new
- cv = ConditionVariable.new
- in_synchronize = false
-
- th = Thread.new do
- m.synchronize do
- in_synchronize = true
- cv.wait(m)
- end
- end
-
- # wait for m to acquire the mutex
- Thread.pass until in_synchronize
- # wait until th is sleeping (ie waiting)
- Thread.pass until th.stop?
-
- m.synchronize { cv.broadcast }.should == cv
-
- th.join
- end
-
it "releases all threads waiting in line for this resource" do
m = Mutex.new
cv = ConditionVariable.new
diff --git a/spec/ruby/library/conditionvariable/signal_spec.rb b/spec/ruby/library/conditionvariable/signal_spec.rb
index bcab42154e..11e4909501 100644
--- a/spec/ruby/library/conditionvariable/signal_spec.rb
+++ b/spec/ruby/library/conditionvariable/signal_spec.rb
@@ -2,33 +2,6 @@ require_relative '../../spec_helper'
require 'thread'
describe "ConditionVariable#signal" do
- it "returns self if nothing to signal" do
- cv = ConditionVariable.new
- cv.signal.should == cv
- end
-
- it "returns self if something is waiting for a signal" do
- m = Mutex.new
- cv = ConditionVariable.new
- in_synchronize = false
-
- th = Thread.new do
- m.synchronize do
- in_synchronize = true
- cv.wait(m)
- end
- end
-
- # wait for m to acquire the mutex
- Thread.pass until in_synchronize
- # wait until th is sleeping (ie waiting)
- Thread.pass until th.stop?
-
- m.synchronize { cv.signal }.should == cv
-
- th.join
- end
-
it "releases the first thread waiting in line for this resource" do
m = Mutex.new
cv = ConditionVariable.new
diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb
index b6cd12ed4e..b545c6c15e 100644
--- a/spec/ruby/library/conditionvariable/wait_spec.rb
+++ b/spec/ruby/library/conditionvariable/wait_spec.rb
@@ -11,7 +11,7 @@ describe "ConditionVariable#wait" do
cv.wait(o, 1234)
end
- it "returns self" do
+ it "can be woken up by ConditionVariable#signal" do
m = Mutex.new
cv = ConditionVariable.new
in_synchronize = false
@@ -19,8 +19,9 @@ describe "ConditionVariable#wait" do
th = Thread.new do
m.synchronize do
in_synchronize = true
- cv.wait(m).should == cv
+ cv.wait(m)
end
+ :success
end
# wait for m to acquire the mutex
@@ -29,7 +30,7 @@ describe "ConditionVariable#wait" do
Thread.pass until th.stop?
m.synchronize { cv.signal }
- th.join
+ th.value.should == :success
end
it "can be interrupted by Thread#run" do