ruby-changes:59936
From: Nobuyoshi <ko1@a...>
Date: Thu, 6 Feb 2020 14:53:28 +0900 (JST)
Subject: [ruby-changes:59936] 3d83e641b1 (master): [ruby/spec] Check by Thread#stop?
https://git.ruby-lang.org/ruby.git/commit/?id=3d83e641b1 From 3d83e641b1a6e13e0e0a59c19536e1dde96891f4 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada <nobu@r...> Date: Thu, 6 Feb 2020 13:36:02 +0900 Subject: [ruby/spec] Check by Thread#stop? Check if threads are stopped by Thread#stop? instead of the status name. diff --git a/spec/ruby/core/mutex/sleep_spec.rb b/spec/ruby/core/mutex/sleep_spec.rb index f5e0d53..6638f5a 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/mutex/sleep_spec.rb#L37 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/mutex/sleep_spec.rb#L63 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 c9c3bfe..d999e66 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/core/mutex/unlock_spec.rb#L17 # 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 a31a044..1dccdf4 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/broadcast_spec.rb#L22 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/broadcast_spec.rb#L50 # 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 04b249a..bcab421 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/signal_spec.rb#L22 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/signal_spec.rb#L50 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/signal_spec.rb#L85 # 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 59d708d..b6cd12e 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/wait_spec.rb#L26 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/wait_spec.rb#L48 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/wait_spec.rb#L70 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/wait_spec.rb#L97 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/wait_spec.rb#L127 # 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 https://github.com/ruby/ruby/blob/trunk/spec/ruby/library/conditionvariable/wait_spec.rb#L158 } 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. -- cgit v0.10.2 -- ML: ruby-changes@q... Info: http://www.atdot.net/~ko1/quickml/