test/lib_read_write.rb in kgio-1.3.1 vs test/lib_read_write.rb in kgio-2.0.0pre1

- old
+ new

@@ -11,13 +11,10 @@ def teardown assert_nothing_raised do @rd.close unless @rd.closed? @wr.close unless @wr.closed? end - assert_nothing_raised do - Kgio.wait_readable = Kgio.wait_writable = nil - end end def test_read_zero assert_equal "", @rd.kgio_read(0) buf = "foo" @@ -95,13 +92,13 @@ begin rv = @wr.kgio_trywrite(wr) case rv when String wr = rv - when Kgio::WaitReadable + when :wait_readable assert false, "should never get here line=#{__LINE__}" - when Kgio::WaitWritable + when :wait_writable IO.select(nil, [ @wr ]) else wr = false end end while wr @@ -120,11 +117,11 @@ assert_equal nil, @wr.kgio_trywrite(10) assert_equal "10", @rd.kgio_tryread(2) end def test_tryread_empty - assert_equal Kgio::WaitReadable, @rd.kgio_tryread(1) + assert_equal :wait_readable, @rd.kgio_tryread(1) end def test_read_too_much assert_equal nil, @wr.kgio_write("hi") assert_equal "hi", @rd.kgio_read(4) @@ -157,25 +154,25 @@ assert_equal tmp_object_id, rv.object_id end def test_trywrite_return_wait_writable tmp = [] - tmp << @wr.kgio_trywrite("HI") until tmp[-1] == Kgio::WaitWritable - assert Kgio::WaitWritable === tmp[-1] - assert(!(Kgio::WaitReadable === tmp[-1])) - assert_equal Kgio::WaitWritable, tmp.pop + tmp << @wr.kgio_trywrite("HI") until tmp[-1] == :wait_writable + assert :wait_writable === tmp[-1] + assert(!(:wait_readable === tmp[-1])) + assert_equal :wait_writable, tmp.pop assert tmp.size > 0 penultimate = tmp.pop assert(penultimate == "I" || penultimate == nil) assert tmp.size > 0 tmp.each { |count| assert_equal nil, count } end def test_tryread_extra_buf_eagain_clears_buffer tmp = "hello world" rv = @rd.kgio_tryread(2, tmp) - assert_equal Kgio::WaitReadable, rv + assert_equal :wait_readable, rv assert_equal "", tmp end def test_tryread_extra_buf_eof_clears_buffer tmp = "hello world" @@ -203,26 +200,24 @@ assert_equal buf, readed end def test_monster_write_wait_writable @wr.instance_variable_set :@nr, 0 - def @wr.wait_writable + def @wr.kgio_wait_writable @nr += 1 IO.select(nil, [self]) end - Kgio.wait_writable = :wait_writable buf = "." * 1024 * 1024 * 10 thr = Thread.new { @wr.kgio_write(buf) } readed = @rd.read(buf.size) thr.join assert_nil thr.value assert_equal buf, readed assert @wr.instance_variable_get(:@nr) > 0 end def test_wait_readable_ruby_default - assert_nothing_raised { Kgio.wait_readable = nil } elapsed = 0 foo = nil t0 = Time.now thr = Thread.new { sleep 1; @wr.write "HELLO" } assert_nothing_raised do @@ -241,11 +236,10 @@ begin nr += @wr.write_nonblock(buf) rescue Errno::EAGAIN break end while true - assert_nothing_raised { Kgio.wait_writable = nil } elapsed = 0 foo = nil t0 = Time.now thr = Thread.new { sleep 1; @rd.readpartial(nr) } assert_nothing_raised do @@ -259,14 +253,13 @@ assert(String === foo || foo == nil) assert_kind_of String, thr.value end def test_wait_readable_method - def @rd.moo + def @rd.kgio_wait_readable defined?(@z) ? raise(RuntimeError, "Hello") : @z = "HI" end - assert_nothing_raised { Kgio.wait_readable = :moo } foo = nil begin foo = @rd.kgio_read(5) assert false rescue RuntimeError => e @@ -275,32 +268,29 @@ assert_equal "HI", @rd.instance_variable_get(:@z) assert_nil foo end def test_tryread_wait_readable_method - def @rd.moo + def @rd.kgio_wait_readable raise "Hello" end - assert_nothing_raised { Kgio.wait_readable = :moo } - assert_equal Kgio::WaitReadable, @rd.kgio_tryread(5) + assert_equal :wait_readable, @rd.kgio_tryread(5) end def test_trywrite_wait_readable_method - def @wr.moo + def @wr.kgio_wait_writable raise "Hello" end - assert_nothing_raised { Kgio.wait_writable = :moo } tmp = [] buf = "." * 1024 10000.times { tmp << @wr.kgio_trywrite(buf) } - assert_equal Kgio::WaitWritable, tmp.pop + assert_equal :wait_writable, tmp.pop end def test_wait_writable_method - def @wr.moo + def @wr.kgio_wait_writable defined?(@z) ? raise(RuntimeError, "Hello") : @z = "HI" end - assert_nothing_raised { Kgio.wait_writable = :moo } n = [] begin loop { n << @wr.kgio_write("HIHIHIHIHIHI") } assert false rescue RuntimeError => e