diff options
Diffstat (limited to 'test/socket/test_tcp.rb')
-rw-r--r-- | test/socket/test_tcp.rb | 51 |
1 files changed, 25 insertions, 26 deletions
diff --git a/test/socket/test_tcp.rb b/test/socket/test_tcp.rb index 73747929e3..7328897d1e 100644 --- a/test/socket/test_tcp.rb +++ b/test/socket/test_tcp.rb @@ -45,36 +45,35 @@ class TestSocket_TCPSocket < Test::Unit::TestCase end def test_recvfrom - svr = TCPServer.new("localhost", 0) - th = Thread.new { - c = svr.accept - c.write "foo" - c.close + TCPServer.open("localhost", 0) {|svr| + th = Thread.new { + c = svr.accept + c.write "foo" + c.close + } + addr = svr.addr + TCPSocket.open(addr[3], addr[1]) {|sock| + assert_equal(["foo", nil], sock.recvfrom(0x10000)) + } + th.join } - addr = svr.addr - sock = TCPSocket.open(addr[3], addr[1]) - assert_equal(["foo", nil], sock.recvfrom(0x10000)) - ensure - th.kill if th - th.join if th end def test_encoding - svr = TCPServer.new("localhost", 0) - th = Thread.new { - c = svr.accept - c.write "foo\r\n" - c.close + TCPServer.open("localhost", 0) {|svr| + th = Thread.new { + c = svr.accept + c.write "foo\r\n" + c.close + } + addr = svr.addr + TCPSocket.open(addr[3], addr[1]) {|sock| + assert_equal(true, sock.binmode?) + s = sock.gets + assert_equal("foo\r\n", s) + assert_equal(Encoding.find("ASCII-8BIT"), s.encoding) + } + th.join } - addr = svr.addr - sock = TCPSocket.open(addr[3], addr[1]) - assert_equal(true, sock.binmode?) - s = sock.gets - assert_equal("foo\r\n", s) - assert_equal(Encoding.find("ASCII-8BIT"), s.encoding) - ensure - th.kill if th - th.join if th - sock.close if sock end end if defined?(TCPSocket) |