1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

[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.
This commit is contained in:
Nobuyoshi Nakada 2020-02-06 15:42:01 +09:00
parent 32adae431d
commit 739fdb7ff0
No known key found for this signature in database
GPG key ID: 4BC7D6DF58D8DF60
3 changed files with 4 additions and 57 deletions

View file

@ -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

View file

@ -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

View file

@ -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