test/lib_read_write.rb in kgio-2.7.3 vs test/lib_read_write.rb in kgio-2.7.4
- old
+ new
@@ -7,14 +7,12 @@
module LibReadWriteTest
RANDOM_BLOB = File.open("/dev/urandom") { |fp| fp.read(10 * 1024 * 1024) }
def teardown
- assert_nothing_raised do
- @rd.close if defined?(@rd) && ! @rd.closed?
- @wr.close if defined?(@wr) && ! @wr.closed?
- end
+ @rd.close if defined?(@rd) && ! @rd.closed?
+ @wr.close if defined?(@wr) && ! @wr.closed?
end
def test_write_empty
assert_nil @wr.kgio_write("")
end
@@ -57,19 +55,21 @@
def test_tryread_shared
a = "." * 0x1000
b = a.dup
@wr.syswrite("a")
+ IO.select([@rd]) # this seems needed on FreeBSD 9.0
assert_equal "a", @rd.kgio_tryread(0x1000, b)
assert_equal "a", b
assert_equal "." * 0x1000, a
end
def test_tryread_shared_2
a = "." * 0x1000
b = a.dup
@wr.syswrite("a")
+ IO.select([@rd]) # this seems needed on FreeBSD 9.0
assert_equal "a", @rd.kgio_tryread(0x1000, a)
assert_equal "a", a
assert_equal "." * 0x1000, b
end
@@ -88,10 +88,11 @@
end
end
def test_tryread_eof
@wr.close
+ IO.select([@rd]) # this seems needed on FreeBSD 9.0
assert_nil @rd.kgio_tryread(5)
end
def test_write_closed
@rd.close
@@ -157,10 +158,11 @@
assert_equal "10", @rd.kgio_read(2)
end
def test_trywrite_conv
assert_equal nil, @wr.kgio_trywrite(10)
+ IO.select([@rd]) # this seems needed on FreeBSD 9.0
assert_equal "10", @rd.kgio_tryread(2)
end
def test_tryread_empty
assert_equal :wait_readable, @rd.kgio_tryread(1)
@@ -182,10 +184,11 @@
assert_equal "i", @rd.kgio_read(1)
end
def test_tryread_short
assert_equal nil, @wr.kgio_trywrite("hi")
+ IO.select([@rd]) # this seems needed on FreeBSD 9.0
assert_equal "h", @rd.kgio_tryread(1)
assert_equal "i", @rd.kgio_tryread(1)
end
def test_read_extra_buf
@@ -219,10 +222,11 @@
end
def test_tryread_extra_buf_eof_clears_buffer
tmp = "hello world"
@wr.close
+ IO.select([@rd]) # this seems needed on FreeBSD 9.0
assert_nil @rd.kgio_tryread(2, tmp)
assert_equal "", tmp
end
def test_monster_trywrite
@@ -262,14 +266,12 @@
def test_wait_readable_ruby_default
elapsed = 0
foo = nil
t0 = Time.now
thr = Thread.new { sleep 1; @wr.write "HELLO" }
- assert_nothing_raised do
- foo = @rd.kgio_read(5)
- elapsed = Time.now - t0
- end
+ foo = @rd.kgio_read(5)
+ elapsed = Time.now - t0
assert elapsed >= 1.0, "elapsed: #{elapsed}"
assert_equal "HELLO", foo
thr.join
assert_equal 5, thr.value
end
@@ -283,14 +285,13 @@
break
end while true
elapsed = 0
foo = nil
t0 = Time.now
- thr = Thread.new { sleep 1; @rd.readpartial(nr) }
- assert_nothing_raised do
- foo = @wr.kgio_write("HELLO")
- elapsed = Time.now - t0
- end
+ thr = Thread.new { sleep 1; @rd.read(nr) }
+ foo = @wr.kgio_write("HELLO")
+ elapsed = Time.now - t0
+
assert_nil foo
if @wr.stat.pipe?
assert elapsed >= 1.0, "elapsed: #{elapsed}"
end
assert(String === foo || foo == nil)