aboutsummaryrefslogtreecommitdiffstats
path: root/spec/ruby/core/mutex
diff options
context:
space:
mode:
authorNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-06 13:36:02 +0900
committerNobuyoshi Nakada <nobu@ruby-lang.org>2020-02-06 14:50:32 +0900
commit3d83e641b1a6e13e0e0a59c19536e1dde96891f4 (patch)
tree6bd0ac843934ea6daed121ea49b1d37bae85f4a0 /spec/ruby/core/mutex
parent34f8e75f9305b0da4ef1b0d4fe9ea3c3f31dcc22 (diff)
downloadruby-3d83e641b1a6e13e0e0a59c19536e1dde96891f4.tar.gz
[ruby/spec] Check by Thread#stop?
Check if threads are stopped by Thread#stop? instead of the status name.
Diffstat (limited to 'spec/ruby/core/mutex')
-rw-r--r--spec/ruby/core/mutex/sleep_spec.rb16
-rw-r--r--spec/ruby/core/mutex/unlock_spec.rb2
2 files changed, 13 insertions, 5 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)