From 739fdb7ff0767ae4a666ca83f61e807c0c6c7115 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Thu, 6 Feb 2020 15:42:01 +0900 Subject: [ruby/spec] Don't care about return values RDoc says nothing about them. Added an example that ConditionVariable#wait can be woken up by ConditionVariable#signal, instead. --- .../library/conditionvariable/broadcast_spec.rb | 27 ---------------------- spec/ruby/library/conditionvariable/signal_spec.rb | 27 ---------------------- spec/ruby/library/conditionvariable/wait_spec.rb | 7 +++--- 3 files changed, 4 insertions(+), 57 deletions(-) (limited to 'spec') diff --git a/spec/ruby/library/conditionvariable/broadcast_spec.rb b/spec/ruby/library/conditionvariable/broadcast_spec.rb index 1dccdf4895..d88159df23 100644 --- a/spec/ruby/library/conditionvariable/broadcast_spec.rb +++ b/spec/ruby/library/conditionvariable/broadcast_spec.rb @@ -2,33 +2,6 @@ require_relative '../../spec_helper' require 'thread' describe "ConditionVariable#broadcast" do - it "returns self if nothing to broadcast to" do - cv = ConditionVariable.new - cv.broadcast.should == cv - end - - it "returns self if something is waiting for a broadcast" do - m = Mutex.new - cv = ConditionVariable.new - in_synchronize = false - - th = Thread.new do - m.synchronize do - in_synchronize = true - cv.wait(m) - end - end - - # wait for m to acquire the mutex - Thread.pass until in_synchronize - # wait until th is sleeping (ie waiting) - Thread.pass until th.stop? - - m.synchronize { cv.broadcast }.should == cv - - th.join - end - it "releases all threads waiting in line for this resource" do m = Mutex.new cv = ConditionVariable.new diff --git a/spec/ruby/library/conditionvariable/signal_spec.rb b/spec/ruby/library/conditionvariable/signal_spec.rb index bcab42154e..11e4909501 100644 --- a/spec/ruby/library/conditionvariable/signal_spec.rb +++ b/spec/ruby/library/conditionvariable/signal_spec.rb @@ -2,33 +2,6 @@ require_relative '../../spec_helper' require 'thread' describe "ConditionVariable#signal" do - it "returns self if nothing to signal" do - cv = ConditionVariable.new - cv.signal.should == cv - end - - it "returns self if something is waiting for a signal" do - m = Mutex.new - cv = ConditionVariable.new - in_synchronize = false - - th = Thread.new do - m.synchronize do - in_synchronize = true - cv.wait(m) - end - end - - # wait for m to acquire the mutex - Thread.pass until in_synchronize - # wait until th is sleeping (ie waiting) - Thread.pass until th.stop? - - m.synchronize { cv.signal }.should == cv - - th.join - end - it "releases the first thread waiting in line for this resource" do m = Mutex.new cv = ConditionVariable.new diff --git a/spec/ruby/library/conditionvariable/wait_spec.rb b/spec/ruby/library/conditionvariable/wait_spec.rb index b6cd12ed4e..b545c6c15e 100644 --- a/spec/ruby/library/conditionvariable/wait_spec.rb +++ b/spec/ruby/library/conditionvariable/wait_spec.rb @@ -11,7 +11,7 @@ describe "ConditionVariable#wait" do cv.wait(o, 1234) end - it "returns self" do + it "can be woken up by ConditionVariable#signal" do m = Mutex.new cv = ConditionVariable.new in_synchronize = false @@ -19,8 +19,9 @@ describe "ConditionVariable#wait" do th = Thread.new do m.synchronize do in_synchronize = true - cv.wait(m).should == cv + cv.wait(m) end + :success end # wait for m to acquire the mutex @@ -29,7 +30,7 @@ describe "ConditionVariable#wait" do Thread.pass until th.stop? m.synchronize { cv.signal } - th.join + th.value.should == :success end it "can be interrupted by Thread#run" do -- cgit v1.2.3