2004-11-29 00:00:46 -05:00
|
|
|
require 'test/unit'
|
2007-12-29 13:39:43 -05:00
|
|
|
require 'timeout'
|
2004-11-29 01:22:42 -05:00
|
|
|
begin
|
|
|
|
require 'io/nonblock'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2004-11-29 00:00:46 -05:00
|
|
|
|
|
|
|
class TestIONonblock < Test::Unit::TestCase
|
2007-11-18 02:18:56 -05:00
|
|
|
def test_flush
|
2004-11-29 00:00:46 -05:00
|
|
|
r,w = IO.pipe
|
|
|
|
w.nonblock = true
|
|
|
|
w.sync = false
|
|
|
|
w << "b"
|
|
|
|
w.flush
|
|
|
|
w << "a" * 4096
|
2004-11-29 00:21:47 -05:00
|
|
|
result = ""
|
2007-12-29 13:39:43 -05:00
|
|
|
timeout(10) {
|
2007-12-30 07:42:20 -05:00
|
|
|
Thread.new {
|
|
|
|
Thread.pass
|
|
|
|
w.close
|
|
|
|
}
|
|
|
|
t = Thread.new {
|
|
|
|
while (Thread.pass; s = r.read(4096))
|
|
|
|
result << s
|
|
|
|
end
|
|
|
|
}
|
|
|
|
w.flush # assert_raise(IOError, "[ruby-dev:24985]") {w.flush}
|
2007-12-29 13:39:43 -05:00
|
|
|
assert_nothing_raised {t.join}
|
|
|
|
}
|
2004-12-07 13:26:12 -05:00
|
|
|
assert_equal(4097, result.size)
|
2004-11-29 00:00:46 -05:00
|
|
|
end
|
2004-11-29 01:22:42 -05:00
|
|
|
end if IO.method_defined?(:nonblock)
|