summaryrefslogtreecommitdiff
path: root/test/io/wait/test_io_wait.rb
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-21 13:40:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2012-11-21 13:40:00 +0000
commite786aa711da8e64734d20acfd9c6b8df0b4515c5 (patch)
treede792c01c3a6f363bc09ec0c3ba4a9c7b709970b /test/io/wait/test_io_wait.rb
parent7d0cabb8f881798da1332becf60096a09fbb6c01 (diff)
io/wait: add IO#wait_writable method
* ext/io/wait/wait.c (io_wait_writable): this is easier to use than IO.select for a single IO object and is immune to the limitations/innefficiency of select() on platforms where poll/ppoll is available. patched by Eric Wong. [Feature #4646] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@37785 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/io/wait/test_io_wait.rb')
-rw-r--r--test/io/wait/test_io_wait.rb36
1 files changed, 36 insertions, 0 deletions
diff --git a/test/io/wait/test_io_wait.rb b/test/io/wait/test_io_wait.rb
index 3cf967e4678..676809cfc77 100644
--- a/test/io/wait/test_io_wait.rb
+++ b/test/io/wait/test_io_wait.rb
@@ -1,3 +1,4 @@
+# -*- coding: us-ascii -*-
require 'test/unit'
require 'timeout'
require 'socket'
@@ -69,4 +70,39 @@ class TestIOWait < Test::Unit::TestCase
Thread.new { sleep 0.01; @w.close }
assert_nil @r.wait
end
+
+ def test_wait_writable
+ assert_equal @w, @w.wait_writable
+ end
+
+ def test_wait_writable_timeout
+ assert_equal @w, @w.wait_writable(0.001)
+ written = fill_pipe
+ assert_nil @w.wait_writable(0.001)
+ @r.read(written)
+ assert_equal @w, @w.wait_writable(0.001)
+ end
+
+ def test_wait_writable_EPIPE
+ fill_pipe
+ @r.close
+ assert_equal @w, @w.wait_writable
+ end
+
+ def test_wait_writable_closed
+ @w.close
+ assert_raises(IOError) { @w.wait_writable }
+ end
+
+private
+
+ def fill_pipe
+ written = 0
+ buf = " " * 4096
+ begin
+ written += @w.write_nonblock(buf)
+ rescue Errno::EAGAIN
+ return written
+ end while true
+ end
end if IO.method_defined?(:wait)