1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00

* test/socket/test_socket.rb (test_connect_timeout): added a test

based on a patch by Eric Wong.  [ruby-core:38910]


git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@32971 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
akr 2011-08-13 20:58:11 +00:00
parent 31e1fce2a3
commit 4db0c519f5
2 changed files with 33 additions and 0 deletions

View file

@ -1,3 +1,8 @@
Sun Aug 14 05:57:01 2011 Tanaka Akira <akr@fsij.org>
* test/socket/test_socket.rb (test_connect_timeout): added a test
based on a patch by Eric Wong. [ruby-core:38910]
Sat Aug 13 22:17:27 2011 Nobuyoshi Nakada <nobu@ruby-lang.org>
* tool/mkconfig.rb: do not make the entries related to sitedir and

View file

@ -430,4 +430,32 @@ class TestSocket < Test::Unit::TestCase
ensure
server.close
end
def test_connect_timeout
host = "127.0.0.1"
server = TCPServer.new(host, 0)
port = server.addr[1]
serv_thread = Thread.new {server.accept}
sock = Socket.tcp(host, port, :connect_timeout => 30)
accepted = serv_thread.value
assert_kind_of TCPSocket, accepted
assert_equal sock, IO.select(nil, [ sock ])[1][0], "not writable"
sock.close
# some platforms may not timeout when the listener queue overflows,
# but we know Linux does with the default listen backlog of SOMAXCONN for
# TCPServer.
assert_raises(Errno::ETIMEDOUT) do
(Socket::SOMAXCONN*2).times do |i|
sock = Socket.tcp(host, port, :connect_timeout => 0)
assert_equal sock, IO.select(nil, [ sock ])[1][0],
"not writable (#{i})"
sock.close
end
end if RUBY_PLATFORM =~ /linux/
ensure
server.close
accepted.close if accepted
sock.close if sock && ! sock.closed?
end
end if defined?(Socket)