summaryrefslogtreecommitdiff
path: root/test/webrick
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-11 06:11:40 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2015-01-11 06:11:40 +0000
commit7c4d749d18e8b471fafb52ce35a957ead075bdea (patch)
tree42ea4b842aac015284a13673455079ee5969433c /test/webrick
parentae752cc546eeddb749604ca1cf4e83ee740ca47c (diff)
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] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@49211 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/webrick')
-rw-r--r--test/webrick/test_utils.rb24
1 files changed, 20 insertions, 4 deletions
diff --git a/test/webrick/test_utils.rb b/test/webrick/test_utils.rb
index d7ef365..9f62c81 100644
--- a/test/webrick/test_utils.rb
+++ b/test/webrick/test_utils.rb
@@ -59,10 +59,26 @@ class TestWEBrickUtils < Test::Unit::TestCase
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