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:
parent
32adae431d
commit
739fdb7ff0
3 changed files with 4 additions and 57 deletions
|
@ -2,33 +2,6 @@ require_relative '../../spec_helper'
|
||||||
require 'thread'
|
require 'thread'
|
||||||
|
|
||||||
describe "ConditionVariable#broadcast" do
|
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
|
it "releases all threads waiting in line for this resource" do
|
||||||
m = Mutex.new
|
m = Mutex.new
|
||||||
cv = ConditionVariable.new
|
cv = ConditionVariable.new
|
||||||
|
|
|
@ -2,33 +2,6 @@ require_relative '../../spec_helper'
|
||||||
require 'thread'
|
require 'thread'
|
||||||
|
|
||||||
describe "ConditionVariable#signal" do
|
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
|
it "releases the first thread waiting in line for this resource" do
|
||||||
m = Mutex.new
|
m = Mutex.new
|
||||||
cv = ConditionVariable.new
|
cv = ConditionVariable.new
|
||||||
|
|
|
@ -11,7 +11,7 @@ describe "ConditionVariable#wait" do
|
||||||
cv.wait(o, 1234)
|
cv.wait(o, 1234)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns self" do
|
it "can be woken up by ConditionVariable#signal" do
|
||||||
m = Mutex.new
|
m = Mutex.new
|
||||||
cv = ConditionVariable.new
|
cv = ConditionVariable.new
|
||||||
in_synchronize = false
|
in_synchronize = false
|
||||||
|
@ -19,8 +19,9 @@ describe "ConditionVariable#wait" do
|
||||||
th = Thread.new do
|
th = Thread.new do
|
||||||
m.synchronize do
|
m.synchronize do
|
||||||
in_synchronize = true
|
in_synchronize = true
|
||||||
cv.wait(m).should == cv
|
cv.wait(m)
|
||||||
end
|
end
|
||||||
|
:success
|
||||||
end
|
end
|
||||||
|
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
|
@ -29,7 +30,7 @@ describe "ConditionVariable#wait" do
|
||||||
Thread.pass until th.stop?
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
m.synchronize { cv.signal }
|
m.synchronize { cv.signal }
|
||||||
th.join
|
th.value.should == :success
|
||||||
end
|
end
|
||||||
|
|
||||||
it "can be interrupted by Thread#run" do
|
it "can be interrupted by Thread#run" do
|
||||||
|
|
Loading…
Add table
Reference in a new issue