From 260d0d0399f902e9c079b3447d67957678c461c5 Mon Sep 17 00:00:00 2001 From: akr Date: Tue, 3 Feb 2009 06:37:06 +0000 Subject: [PATCH] add a test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22006 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/socket/test_socket.rb | 26 ++++++++++++++++++++++++++ 1 file changed, 26 insertions(+) diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb index d933d9c0cc..d0f401b6f2 100644 --- a/test/socket/test_socket.rb +++ b/test/socket/test_socket.rb @@ -143,6 +143,32 @@ class TestSocket < Test::Unit::TestCase } } end + + def test_accept_loop + Dir.mktmpdir {|tmpdir| + tcp_servers = [] + clients = [] + accepted = [] + begin + tcp_servers = Socket.tcp_server_sockets(0) + unix_server = Socket.unix_server_socket("#{tmpdir}/sock") + tcp_servers.each {|s| + clients << s.local_address.connect + } + clients << unix_server.local_address.connect + Socket.accept_loop(tcp_servers, unix_server) {|s| + accepted << s + break if clients.length == accepted.length + } + assert_equal(clients.length, accepted.length) + ensure + tcp_servers.each {|s| s.close if !s.closed? } + unix_server.close if !unix_server.closed? + clients.each {|s| s.close if !s.closed? } + accepted.each {|s| s.close if !s.closed? } + end + } + end end end if defined?(Socket)