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
|
||||
th = Thread.new { m.lock; locked = true; m.sleep }
|
||||
Thread.pass until locked
|
||||
Thread.pass while th.status and th.status != "sleep"
|
||||
Thread.pass until th.stop?
|
||||
m.locked?.should be_false
|
||||
th.run
|
||||
th.join
|
||||
|
@ -63,15 +63,23 @@ describe "Mutex#sleep" do
|
|||
end
|
||||
end
|
||||
Thread.pass until locked
|
||||
Thread.pass while th.status and th.status != "sleep"
|
||||
Thread.pass until th.stop?
|
||||
th.raise(Exception)
|
||||
th.value.should be_true
|
||||
end
|
||||
|
||||
it "returns the rounded number of seconds asleep" do
|
||||
m = Mutex.new
|
||||
m.lock
|
||||
m.sleep(0.001).should be_kind_of(Integer)
|
||||
locked = false
|
||||
th = Thread.start do
|
||||
m.lock
|
||||
locked = true
|
||||
m.sleep
|
||||
end
|
||||
Thread.pass until locked
|
||||
Thread.pass until th.stop?
|
||||
th.wakeup
|
||||
th.value.should be_kind_of(Integer)
|
||||
end
|
||||
|
||||
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
|
||||
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)
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ describe "ConditionVariable#broadcast" do
|
|||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# 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
|
||||
|
||||
|
@ -50,7 +50,7 @@ describe "ConditionVariable#broadcast" do
|
|||
# wait for all threads to acquire the mutex the first time
|
||||
Thread.pass until m.synchronize { r1.size == threads.size }
|
||||
# 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
|
||||
m.synchronize do
|
||||
|
|
|
@ -22,7 +22,7 @@ describe "ConditionVariable#signal" do
|
|||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# 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
|
||||
|
||||
|
@ -50,7 +50,7 @@ describe "ConditionVariable#signal" do
|
|||
# wait for all threads to acquire the mutex the first time
|
||||
Thread.pass until m.synchronize { r1.size == threads.size }
|
||||
# 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
|
||||
100.times do |i|
|
||||
|
@ -85,7 +85,7 @@ describe "ConditionVariable#signal" do
|
|||
|
||||
# Make sure t1 is waiting for a signal before launching t2.
|
||||
Thread.pass until in_synchronize
|
||||
Thread.pass until t1.status == 'sleep'
|
||||
Thread.pass until t1.stop?
|
||||
|
||||
t2 = Thread.new do
|
||||
m.synchronize do
|
||||
|
|
|
@ -26,7 +26,7 @@ describe "ConditionVariable#wait" do
|
|||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# 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 }
|
||||
th.join
|
||||
|
@ -48,7 +48,7 @@ describe "ConditionVariable#wait" do
|
|||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# wait until th is sleeping (ie waiting)
|
||||
Thread.pass while th.status and th.status != "sleep"
|
||||
Thread.pass until th.stop?
|
||||
|
||||
th.run
|
||||
th.value.should == :success
|
||||
|
@ -70,7 +70,7 @@ describe "ConditionVariable#wait" do
|
|||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# wait until th is sleeping (ie waiting)
|
||||
Thread.pass while th.status and th.status != "sleep"
|
||||
Thread.pass until th.stop?
|
||||
|
||||
th.wakeup
|
||||
th.value.should == :success
|
||||
|
@ -97,7 +97,7 @@ describe "ConditionVariable#wait" do
|
|||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# wait until th is sleeping (ie waiting)
|
||||
Thread.pass while th.status and th.status != "sleep"
|
||||
Thread.pass until th.stop?
|
||||
|
||||
th.kill
|
||||
th.join
|
||||
|
@ -127,7 +127,7 @@ describe "ConditionVariable#wait" do
|
|||
# wait for m to acquire the mutex
|
||||
Thread.pass until in_synchronize
|
||||
# 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
|
||||
|
@ -158,7 +158,7 @@ describe "ConditionVariable#wait" do
|
|||
}
|
||||
|
||||
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
|
||||
threads.each { |t|
|
||||
# Cause interactions with the waiting threads.
|
||||
|
|
Loading…
Add table
Reference in a new issue