summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-13 20:58:11 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2011-08-13 20:58:11 +0000
commit4db0c519f51a891cadda08981e9e0f7f2b3f3f81 (patch)
treec9d8947e3f97ea57f6cf7d6b7215c9837904d9a0
parent31e1fce2a3a4ba971aed17cf6544d04649ba4dc9 (diff)
* 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
-rw-r--r--ChangeLog5
-rw-r--r--test/socket/test_socket.rb28
2 files changed, 33 insertions, 0 deletions
diff --git a/ChangeLog b/ChangeLog
index 567a36deba..90360bb855 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -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
diff --git a/test/socket/test_socket.rb b/test/socket/test_socket.rb
index b3b6fee5ef..dd1e5c87c0 100644
--- a/test/socket/test_socket.rb
+++ b/test/socket/test_socket.rb
@@ -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)