From 1c4e6066bede05c7c437b7690ce67ef9e51439c0 Mon Sep 17 00:00:00 2001 From: naruse Date: Tue, 5 Jun 2012 20:10:50 +0000 Subject: Split one big test to seven tests. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/ruby/test_io.rb | 117 +++++++++++++++++++++++++++++++++------------------ 1 file changed, 75 insertions(+), 42 deletions(-) (limited to 'test/ruby') diff --git a/test/ruby/test_io.rb b/test/ruby/test_io.rb index be5a3331f0..8dd1f10480 100644 --- a/test/ruby/test_io.rb +++ b/test/ruby/test_io.rb @@ -534,10 +534,8 @@ class TestIO < Test::Unit::TestCase end end - def test_copy_stream_socket - return unless defined? UNIXSocket + def test_copy_stream_socket1 mkcdtmpdir { - content = "foobar" File.open("src", "w") {|f| f << content } @@ -547,7 +545,11 @@ class TestIO < Test::Unit::TestCase s1.close assert_equal(content, s2.read) } + } + end if defined? UNIXSocket + def test_copy_stream_socket2 + mkcdtmpdir { bigcontent = "abc" * 123456 File.open("bigsrc", "w") {|f| f << bigcontent } @@ -559,6 +561,13 @@ class TestIO < Test::Unit::TestCase result = t.value assert_equal(bigcontent, result) } + } + end if defined? UNIXSocket + + def test_copy_stream_socket3 + mkcdtmpdir { + bigcontent = "abc" * 123456 + File.open("bigsrc", "w") {|f| f << bigcontent } with_socketpair {|s1, s2| t = Thread.new { s2.read } @@ -568,6 +577,13 @@ class TestIO < Test::Unit::TestCase result = t.value assert_equal(bigcontent[0,10000], result) } + } + end if defined? UNIXSocket + + def test_copy_stream_socket4 + mkcdtmpdir { + bigcontent = "abc" * 123456 + File.open("bigsrc", "w") {|f| f << bigcontent } File.open("bigsrc") {|f| assert_equal(0, f.pos) @@ -581,6 +597,13 @@ class TestIO < Test::Unit::TestCase assert_equal(bigcontent[100..-1], result) } } + } + end if defined? UNIXSocket + + def test_copy_stream_socket5 + mkcdtmpdir { + bigcontent = "abc" * 123456 + File.open("bigsrc", "w") {|f| f << bigcontent } File.open("bigsrc") {|f| assert_equal(bigcontent[0,100], f.read(100)) @@ -595,54 +618,64 @@ class TestIO < Test::Unit::TestCase assert_equal(bigcontent[100..-1], result) } } + } + end if defined? UNIXSocket + def test_copy_stream_socket6 + mkcdtmpdir { megacontent = "abc" * 1234567 File.open("megasrc", "w") {|f| f << megacontent } - if have_nonblock? - with_socketpair {|s1, s2| - begin - s1.nonblock = true - rescue Errno::EBADF - skip "nonblocking IO for pipe is not implemented" - end - t = Thread.new { s2.read } - ret = IO.copy_stream("megasrc", s1) - assert_equal(megacontent.bytesize, ret) - s1.close - result = t.value - assert_equal(megacontent, result) - } - with_socketpair {|s1, s2| + with_socketpair {|s1, s2| + begin + s1.nonblock = true + rescue Errno::EBADF + skip "nonblocking IO for pipe is not implemented" + end + t = Thread.new { s2.read } + ret = IO.copy_stream("megasrc", s1) + assert_equal(megacontent.bytesize, ret) + s1.close + result = t.value + assert_equal(megacontent, result) + } + } + end if defined? UNIXSocket + + def test_copy_stream_socket7 + mkcdtmpdir { + megacontent = "abc" * 1234567 + File.open("megasrc", "w") {|f| f << megacontent } + + with_socketpair {|s1, s2| + begin + s1.nonblock = true + rescue Errno::EBADF + skip "nonblocking IO for pipe is not implemented" + end + trapping_usr1 do + nr = 30 begin - s1.nonblock = true - rescue Errno::EBADF - skip "nonblocking IO for pipe is not implemented" - end - trapping_usr1 do - nr = 30 - begin - pid = fork do - s1.close - IO.select([s2]) - Process.kill(:USR1, Process.ppid) - s2.read - end - s2.close - nr.times do - assert_equal megacontent.bytesize, IO.copy_stream("megasrc", s1) - end - assert_equal(1, @usr1_rcvd) - ensure + pid = fork do s1.close - _, status = Process.waitpid2(pid) if pid + IO.select([s2]) + Process.kill(:USR1, Process.ppid) + s2.read end - assert status.success?, status.inspect + s2.close + nr.times do + assert_equal megacontent.bytesize, IO.copy_stream("megasrc", s1) + end + assert_equal(1, @usr1_rcvd) + ensure + s1.close + _, status = Process.waitpid2(pid) if pid end - } - end + assert status.success?, status.inspect + end + } } - end + end if defined? UNIXSocket and IO.method_defined?("nonblock=") def test_copy_stream_strio src = StringIO.new("abcd") -- cgit v1.2.3