diff options
author | Nobuyoshi Nakada <[email protected]> | 2020-02-06 13:36:02 +0900 |
---|---|---|
committer | Nobuyoshi Nakada <[email protected]> | 2020-02-06 14:50:32 +0900 |
commit | 3d83e641b1a6e13e0e0a59c19536e1dde96891f4 (patch) | |
tree | 6bd0ac843934ea6daed121ea49b1d37bae85f4a0 | |
parent | 34f8e75f9305b0da4ef1b0d4fe9ea3c3f31dcc22 (diff) |
[ruby/spec] Check by Thread#stop?
Check if threads are stopped by Thread#stop? instead of the status
name.
-rw-r--r-- | spec/ruby/core/mutex/sleep_spec.rb | 16 | ||||
-rw-r--r-- | spec/ruby/core/mutex/unlock_spec.rb | 2 | ||||
-rw-r--r-- | spec/ruby/library/conditionvariable/broadcast_spec.rb | 4 | ||||
-rw-r--r-- | spec/ruby/library/conditionvariable/signal_spec.rb | 6 | ||||
-rw-r--r-- | spec/ruby/library/conditionvariable/wait_spec.rb | 12 |
5 files changed, 24 insertions, 16 deletions
diff --git a/spec/ruby/core/mutex/sleep_spec.rb b/spec/ruby/core/mutex/sleep_spec.rb index f5e0d53036..6638f5a5a2 100644 --- a/spec/ruby/core/mutex/sleep_spec.rb +++ b/spec/ruby/core/mutex/sleep_spec.rb @@ -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 diff --git a/spec/ruby/core/mutex/unlock_spec.rb b/spec/ruby/core/mutex/unlock_spec.rb index c9c3bfe14f..d999e66842 100644 --- a/spec/ruby/core/mutex/unlock_spec.rb +++ b/spec/ruby/core/mutex/unlock_spec.rb @@ -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) diff --git a/spec/ruby/library/conditionvariable/broadcast_spec.rb b/spec/ruby/library/conditionvariable/broadcast_spec.rb index a31a0443bd..1dccdf4895 100644 --- a/spec/ruby/library/conditionvariable/broadcast_spec.rb +++ b/spec/ruby/library/conditionvariable/broadcast_spec.rb @@ -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 diff --git a/spec/ruby/library/conditionvariable/signal_spec.rb b/spec/ruby/library/conditionvariable/signal_spec.rb index 04b249a6c6..bcab42154e 100644 --- a/spec/ruby/library/conditionvariable/signal_spec.rb +++ b/spec/ruby/library/conditionvariable/signal_spec.rb @@ -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 diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb index 59d708d7e6..b6cd12ed4e 100644 --- a/spec/ruby/library/conditionvariable/wait_spec.rb +++ b/spec/ruby/library/conditionvariable/wait_spec.rb @@ -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. |