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
|
|
|
|
2007-02-20 01:11:37 -05:00
|
|
|
Thread.abort_on_exception = true
|
2004-11-29 00:00:46 -05:00
|
|
|
class TestIONonblock < Test::Unit::TestCase
|
2007-11-18 02:18:56 -05:00
|
|
|
def test_flush
|
2007-02-20 01:11:37 -05:00
|
|
|
flunk "IO#close can't interrupt IO blocking on YARV"
|
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
|
|
|
|
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
|
|
|
}
|
2007-11-18 02:18:56 -05:00
|
|
|
assert_raise(IOError, "[ruby-dev:24985]") {w.flush}
|
2004-12-07 13:26:12 -05:00
|
|
|
assert_nothing_raised {t.join}
|
|
|
|
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)
|