Skip to content

Commit

Permalink
Split one big test to seven tests.
Browse files Browse the repository at this point in the history
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@35932 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
  • Loading branch information
nurse committed Jun 5, 2012
1 parent c8d6b6e commit 1c4e606
Showing 1 changed file with 75 additions and 42 deletions.
117 changes: 75 additions & 42 deletions test/ruby/test_io.rb
Original file line number Diff line number Diff line change
Expand Up @@ -534,10 +534,8 @@ def with_socketpair
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 }

Expand All @@ -547,7 +545,11 @@ def test_copy_stream_socket
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 }

Expand All @@ -559,6 +561,13 @@ def test_copy_stream_socket
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 }
Expand All @@ -568,6 +577,13 @@ def test_copy_stream_socket
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)
Expand All @@ -581,6 +597,13 @@ def test_copy_stream_socket
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))
Expand All @@ -595,54 +618,64 @@ def test_copy_stream_socket
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")
Expand Down

0 comments on commit 1c4e606

Please sign in to comment.