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

ruby-changes:37130

From: nobu <ko1@a...>
Date: Sun, 11 Jan 2015 15:11:53 +0900 (JST)
Subject: [ruby-changes:37130] nobu:r49211 (trunk): test_utils.rb: dynamically chosen port number

nobu	2015-01-11 15:11:40 +0900 (Sun, 11 Jan 2015)

  New Revision: 49211

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

  Log:
    test_utils.rb: dynamically chosen port number
    
    * test/webrick/test_utils.rb (test_create_listeners): use
      dynamically chosen port number, not hardcoded port number.
      [ruby-core:67508]

  Modified files:
    trunk/ChangeLog
    trunk/test/webrick/test_utils.rb
Index: ChangeLog
===================================================================
--- ChangeLog	(revision 49210)
+++ ChangeLog	(revision 49211)
@@ -1,3 +1,9 @@ https://github.com/ruby/ruby/blob/trunk/ChangeLog#L1
+Sun Jan 11 15:11:38 2015  Nobuyoshi Nakada  <nobu@r...>
+
+	* test/webrick/test_utils.rb (test_create_listeners): use
+	  dynamically chosen port number, not hardcoded port number.
+	  [ruby-core:67508]
+
 Sat Jan 10 12:57:12 2015  SHIBATA Hiroshi  <shibata.hiroshi@g...>
 
 	* ext/zlib/zlib.c: fix document of method signatures.
Index: test/webrick/test_utils.rb
===================================================================
--- test/webrick/test_utils.rb	(revision 49210)
+++ test/webrick/test_utils.rb	(revision 49211)
@@ -59,10 +59,26 @@ class TestWEBrickUtils < Test::Unit::Tes https://github.com/ruby/ruby/blob/trunk/test/webrick/test_utils.rb#L59
   end
 
   def test_create_listeners
-    listeners = WEBrick::Utils.create_listeners("127.0.0.1", "9999")
-    srv = listeners.first
-    assert_equal true, srv.is_a?(TCPServer)
-    assert_equal ["AF_INET", 9999, "127.0.0.1", "127.0.0.1"], srv.addr
+    addr = listener_address(0)
+    port = addr.slice!(1)
+    assert_kind_of(Integer, port, "dynamically chosen port number")
+    assert_equal(["AF_INET", "127.0.0.1", "127.0.0.1"], addr)
+
+    assert_equal(["AF_INET", port, "127.0.0.1", "127.0.0.1"],
+                 listener_address(port),
+                 "specific port number")
+
+    assert_equal(["AF_INET", port, "127.0.0.1", "127.0.0.1"],
+                 listener_address(port.to_s),
+                 "specific port number string")
   end
 
+  def listener_address(port)
+    listeners = WEBrick::Utils.create_listeners("127.0.0.1", port)
+    srv = listeners.first
+    assert_kind_of TCPServer, srv
+    srv.addr
+  ensure
+    listeners.each(&:close) if listeners
+  end
 end

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

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