diff options
Diffstat (limited to 'spec/ruby/library/io-wait/wait_spec.rb')
-rw-r--r-- | spec/ruby/library/io-wait/wait_spec.rb | 113 |
1 files changed, 60 insertions, 53 deletions
diff --git a/spec/ruby/library/io-wait/wait_spec.rb b/spec/ruby/library/io-wait/wait_spec.rb index d968c38774..fc07c6a8d9 100644 --- a/spec/ruby/library/io-wait/wait_spec.rb +++ b/spec/ruby/library/io-wait/wait_spec.rb @@ -24,74 +24,81 @@ describe "IO#wait" do @w.close unless @w.closed? end - ruby_version_is "3.0" do - context "[events, timeout] passed" do - ruby_version_is "3.0"..."3.2" do - it "returns self when the READABLE event is ready during the timeout" do - @w.write('data to read') - @r.wait(IO::READABLE, 2).should.equal?(@r) - end - - it "returns self when the WRITABLE event is ready during the timeout" do - @w.wait(IO::WRITABLE, 0).should.equal?(@w) - end + context "[events, timeout] passed" do + ruby_version_is ""..."3.2" do + it "returns self when the READABLE event is ready during the timeout" do + @w.write('data to read') + @r.wait(IO::READABLE, 2).should.equal?(@r) end - ruby_version_is "3.2" do - it "returns events mask when the READABLE event is ready during the timeout" do - @w.write('data to read') - @r.wait(IO::READABLE, 2).should == IO::READABLE - end + it "returns self when the WRITABLE event is ready during the timeout" do + @w.wait(IO::WRITABLE, 0).should.equal?(@w) + end + end + + ruby_version_is "3.2" do + it "returns events mask when the READABLE event is ready during the timeout" do + @w.write('data to read') + @r.wait(IO::READABLE, 2).should == IO::READABLE + end - it "returns events mask when the WRITABLE event is ready during the timeout" do - @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE - end + it "returns events mask when the WRITABLE event is ready during the timeout" do + @w.wait(IO::WRITABLE, 0).should == IO::WRITABLE end + end - ruby_version_is "3.0" do - it "waits for the READABLE event to be ready" do - queue = Queue.new - thread = Thread.new { queue.pop; sleep 1; @w.write('data to read') }; + it "waits for the READABLE event to be ready" do + @r.wait(IO::READABLE, 0).should == nil - queue.push('signal'); - @r.wait(IO::READABLE, 2).should_not == nil + @w.write('data to read') + @r.wait(IO::READABLE, 0).should_not == nil + end - thread.join - end + it "waits for the WRITABLE event to be ready" do + written_bytes = IOWaitSpec.exhaust_write_buffer(@w) + @w.wait(IO::WRITABLE, 0).should == nil - it "waits for the WRITABLE event to be ready" do - written_bytes = IOWaitSpec.exhaust_write_buffer(@w) + @r.read(written_bytes) + @w.wait(IO::WRITABLE, 0).should_not == nil + end - queue = Queue.new - thread = Thread.new { queue.pop; sleep 1; @r.read(written_bytes) }; + it "returns nil when the READABLE event is not ready during the timeout" do + @w.wait(IO::READABLE, 0).should == nil + end - queue.push('signal'); - @w.wait(IO::WRITABLE, 2).should_not == nil + it "returns nil when the WRITABLE event is not ready during the timeout" do + IOWaitSpec.exhaust_write_buffer(@w) + @w.wait(IO::WRITABLE, 0).should == nil + end - thread.join - end + it "raises IOError when io is closed (closed stream (IOError))" do + @io.close + -> { @io.wait(IO::READABLE, 0) }.should raise_error(IOError, "closed stream") + end - it "returns nil when the READABLE event is not ready during the timeout" do - @w.wait(IO::READABLE, 0).should == nil - end + ruby_version_is "3.2" do + it "raises ArgumentError when events is not positive" do + -> { @w.wait(0, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") + -> { @w.wait(-1, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") + end + end - it "returns nil when the WRITABLE event is not ready during the timeout" do - IOWaitSpec.exhaust_write_buffer(@w) - @w.wait(IO::WRITABLE, 0).should == nil - end + it "changes thread status to 'sleep' when waits for READABLE event" do + t = Thread.new { @r.wait(IO::READABLE, 10) } + sleep 1 + t.status.should == 'sleep' + t.kill + t.join # Thread#kill doesn't wait for the thread to end + end - it "raises IOError when io is closed (closed stream (IOError))" do - @io.close - -> { @io.wait(IO::READABLE, 0) }.should raise_error(IOError, "closed stream") - end + it "changes thread status to 'sleep' when waits for WRITABLE event" do + written_bytes = IOWaitSpec.exhaust_write_buffer(@w) - ruby_version_is "3.2" do - it "raises ArgumentError when events is not positive" do - -> { @w.wait(0, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") - -> { @w.wait(-1, 0) }.should raise_error(ArgumentError, "Events must be positive integer!") - end - end - end + t = Thread.new { @w.wait(IO::WRITABLE, 10) } + sleep 1 + t.status.should == 'sleep' + t.kill + t.join # Thread#kill doesn't wait for the thread to end end end |