[前][次][番号順一覧][スレッド一覧]

ruby-changes:20922

From: akr <ko1@a...>
Date: Sun, 14 Aug 2011 05:58:23 +0900 (JST)
Subject: [ruby-changes:20922] akr:r32971 (trunk): * test/socket/test_socket.rb (test_connect_timeout): added a test

akr	2011-08-14 05:58:11 +0900 (Sun, 14 Aug 2011)

  New Revision: 32971

  http://svn.ruby-lang.org/cgi-bin/viewvc.cgi?view=rev&revision=32971

  Log:
    * test/socket/test_socket.rb (test_connect_timeout): added a test
      based on a patch by Eric Wong.  [ruby-core:38910]

  Modified files:
    trunk/ChangeLog
    trunk/test/socket/test_socket.rb

Index: ChangeLog
===================================================================
--- ChangeLog	(revision 32970)
+++ ChangeLog	(revision 32971)
@@ -1,3 +1,8 @@
+Sun Aug 14 05:57:01 2011  Tanaka Akira  <akr@f...>
+
+	* 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@r...>
 
 	* tool/mkconfig.rb: do not make the entries related to sitedir and
Index: test/socket/test_socket.rb
===================================================================
--- test/socket/test_socket.rb	(revision 32970)
+++ test/socket/test_socket.rb	(revision 32971)
@@ -430,4 +430,32 @@
   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)

--
ML: ruby-changes@q...
Info: http://www.atdot.net/~ko1/quickml/

[前][次][番号順一覧][スレッド一覧]