mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
[ruby/spec] Check by Thread#stop?
Check if threads are stopped by Thread#stop? instead of the status name.
This commit is contained in:
parent
34f8e75f93
commit
3d83e641b1
5 changed files with 24 additions and 16 deletions
|
@ -37,7 +37,7 @@ describe "Mutex#sleep" do
|
||||||
locked = false
|
locked = false
|
||||||
th = Thread.new { m.lock; locked = true; m.sleep }
|
th = Thread.new { m.lock; locked = true; m.sleep }
|
||||||
Thread.pass until locked
|
Thread.pass until locked
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
m.locked?.should be_false
|
m.locked?.should be_false
|
||||||
th.run
|
th.run
|
||||||
th.join
|
th.join
|
||||||
|
@ -63,15 +63,23 @@ describe "Mutex#sleep" do
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
Thread.pass until locked
|
Thread.pass until locked
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
th.raise(Exception)
|
th.raise(Exception)
|
||||||
th.value.should be_true
|
th.value.should be_true
|
||||||
end
|
end
|
||||||
|
|
||||||
it "returns the rounded number of seconds asleep" do
|
it "returns the rounded number of seconds asleep" do
|
||||||
m = Mutex.new
|
m = Mutex.new
|
||||||
|
locked = false
|
||||||
|
th = Thread.start do
|
||||||
m.lock
|
m.lock
|
||||||
m.sleep(0.001).should be_kind_of(Integer)
|
locked = true
|
||||||
|
m.sleep
|
||||||
|
end
|
||||||
|
Thread.pass until locked
|
||||||
|
Thread.pass until th.stop?
|
||||||
|
th.wakeup
|
||||||
|
th.value.should be_kind_of(Integer)
|
||||||
end
|
end
|
||||||
|
|
||||||
it "wakes up when requesting sleep times near or equal to zero" do
|
it "wakes up when requesting sleep times near or equal to zero" do
|
||||||
|
|
|
@ -17,7 +17,7 @@ describe "Mutex#unlock" do
|
||||||
|
|
||||||
# avoid race on mutex.lock
|
# avoid race on mutex.lock
|
||||||
Thread.pass until mutex.locked?
|
Thread.pass until mutex.locked?
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
-> { mutex.unlock }.should raise_error(ThreadError)
|
-> { mutex.unlock }.should raise_error(ThreadError)
|
||||||
|
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe "ConditionVariable#broadcast" do
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
# wait until th is sleeping (ie waiting)
|
# wait until th is sleeping (ie waiting)
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
m.synchronize { cv.broadcast }.should == cv
|
m.synchronize { cv.broadcast }.should == cv
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ describe "ConditionVariable#broadcast" do
|
||||||
# wait for all threads to acquire the mutex the first time
|
# wait for all threads to acquire the mutex the first time
|
||||||
Thread.pass until m.synchronize { r1.size == threads.size }
|
Thread.pass until m.synchronize { r1.size == threads.size }
|
||||||
# wait until all threads are sleeping (ie waiting)
|
# wait until all threads are sleeping (ie waiting)
|
||||||
Thread.pass until threads.all? {|th| th.status == "sleep" }
|
Thread.pass until threads.all?(&:stop?)
|
||||||
|
|
||||||
r2.should be_empty
|
r2.should be_empty
|
||||||
m.synchronize do
|
m.synchronize do
|
||||||
|
|
|
@ -22,7 +22,7 @@ describe "ConditionVariable#signal" do
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
# wait until th is sleeping (ie waiting)
|
# wait until th is sleeping (ie waiting)
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
m.synchronize { cv.signal }.should == cv
|
m.synchronize { cv.signal }.should == cv
|
||||||
|
|
||||||
|
@ -50,7 +50,7 @@ describe "ConditionVariable#signal" do
|
||||||
# wait for all threads to acquire the mutex the first time
|
# wait for all threads to acquire the mutex the first time
|
||||||
Thread.pass until m.synchronize { r1.size == threads.size }
|
Thread.pass until m.synchronize { r1.size == threads.size }
|
||||||
# wait until all threads are sleeping (ie waiting)
|
# wait until all threads are sleeping (ie waiting)
|
||||||
Thread.pass until threads.all? {|th| th.status == "sleep" }
|
Thread.pass until threads.all?(&:stop?)
|
||||||
|
|
||||||
r2.should be_empty
|
r2.should be_empty
|
||||||
100.times do |i|
|
100.times do |i|
|
||||||
|
@ -85,7 +85,7 @@ describe "ConditionVariable#signal" do
|
||||||
|
|
||||||
# Make sure t1 is waiting for a signal before launching t2.
|
# Make sure t1 is waiting for a signal before launching t2.
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
Thread.pass until t1.status == 'sleep'
|
Thread.pass until t1.stop?
|
||||||
|
|
||||||
t2 = Thread.new do
|
t2 = Thread.new do
|
||||||
m.synchronize do
|
m.synchronize do
|
||||||
|
|
|
@ -26,7 +26,7 @@ describe "ConditionVariable#wait" do
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
# wait until th is sleeping (ie waiting)
|
# wait until th is sleeping (ie waiting)
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
m.synchronize { cv.signal }
|
m.synchronize { cv.signal }
|
||||||
th.join
|
th.join
|
||||||
|
@ -48,7 +48,7 @@ describe "ConditionVariable#wait" do
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
# wait until th is sleeping (ie waiting)
|
# wait until th is sleeping (ie waiting)
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
th.run
|
th.run
|
||||||
th.value.should == :success
|
th.value.should == :success
|
||||||
|
@ -70,7 +70,7 @@ describe "ConditionVariable#wait" do
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
# wait until th is sleeping (ie waiting)
|
# wait until th is sleeping (ie waiting)
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
th.wakeup
|
th.wakeup
|
||||||
th.value.should == :success
|
th.value.should == :success
|
||||||
|
@ -97,7 +97,7 @@ describe "ConditionVariable#wait" do
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
# wait until th is sleeping (ie waiting)
|
# wait until th is sleeping (ie waiting)
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
th.kill
|
th.kill
|
||||||
th.join
|
th.join
|
||||||
|
@ -127,7 +127,7 @@ describe "ConditionVariable#wait" do
|
||||||
# wait for m to acquire the mutex
|
# wait for m to acquire the mutex
|
||||||
Thread.pass until in_synchronize
|
Thread.pass until in_synchronize
|
||||||
# wait until th is sleeping (ie waiting)
|
# wait until th is sleeping (ie waiting)
|
||||||
Thread.pass while th.status and th.status != "sleep"
|
Thread.pass until th.stop?
|
||||||
|
|
||||||
m.synchronize {
|
m.synchronize {
|
||||||
cv.signal
|
cv.signal
|
||||||
|
@ -158,7 +158,7 @@ describe "ConditionVariable#wait" do
|
||||||
}
|
}
|
||||||
|
|
||||||
Thread.pass until m.synchronize { events.size } == n_threads
|
Thread.pass until m.synchronize { events.size } == n_threads
|
||||||
Thread.pass while threads.any? { |th| th.status and th.status != "sleep" }
|
Thread.pass until threads.any?(&:stop?)
|
||||||
m.synchronize do
|
m.synchronize do
|
||||||
threads.each { |t|
|
threads.each { |t|
|
||||||
# Cause interactions with the waiting threads.
|
# Cause interactions with the waiting threads.
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue