2004-11-29 00:00:46 -05:00
|
|
|
require 'test/unit'
|
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
|
|
|
|
def test_flush # [ruby-dev:24985]
|
|
|
|
r,w = IO.pipe
|
|
|
|
w.nonblock = true
|
|
|
|
w.sync = false
|
|
|
|
w << "b"
|
|
|
|
w.flush
|
|
|
|
w << "a" * 4096
|
|
|
|
Thread.new {
|
|
|
|
Thread.pass
|
|
|
|
w.close
|
|
|
|
}
|
2004-11-29 00:21:47 -05:00
|
|
|
result = ""
|
|
|
|
t = Thread.new {
|
|
|
|
while (Thread.pass; s = r.read(4096))
|
|
|
|
result << s
|
|
|
|
end
|
2004-11-29 00:00:46 -05:00
|
|
|
}
|
|
|
|
assert_raise(IOError) {w.flush}
|
2004-11-29 00:21:47 -05:00
|
|
|
t.join
|
|
|
|
assert_equal("b", result)
|
2004-11-29 00:00:46 -05:00
|
|
|
end
|
2004-11-29 01:22:42 -05:00
|
|
|
end if IO.method_defined?(:nonblock)
|