From 0d28652c3e7388f0eb253baa5b3a697acf6295a1 Mon Sep 17 00:00:00 2001 From: schneems Date: Fri, 16 Mar 2018 16:26:46 -0500 Subject: [PATCH] Avoid hardcoding ports When a test that boots a server fails it may not properly close out the port. When this happens there is a cascading failure as all other tests that use that port also fail. It becomes hard to find the actual failure reason. This commit uses a new number of every time port is used. --- test/helper.rb | 9 +++++++++ test/test_persistent.rb | 6 +++--- test/test_puma_server_ssl.rb | 2 +- test/test_tcp_rack.rb | 2 +- 4 files changed, 14 insertions(+), 5 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 887964a6..d230c60b 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -43,6 +43,15 @@ def hit(uris) end end +module UniquePort + @port = 3211 + + def self.call + @port += 1 + @port + end +end + module TimeoutEveryTestCase # our own subclass so we never confused different timeouts class TestTookTooLong < Timeout::Error diff --git a/test/test_persistent.rb b/test/test_persistent.rb index 94d7cc19..06ec90aa 100644 --- a/test/test_persistent.rb +++ b/test/test_persistent.rb @@ -21,14 +21,14 @@ class TestPersistent < Minitest::Test end @host = "127.0.0.1" - @port = 9988 + @port = UniquePort.call @server = Puma::Server.new @simple - @server.add_tcp_listener "127.0.0.1", 9988 + @server.add_tcp_listener "127.0.0.1", @port @server.max_threads = 1 @server.run - @client = TCPSocket.new "127.0.0.1", 9988 + @client = TCPSocket.new "127.0.0.1", @port end def teardown diff --git a/test/test_puma_server_ssl.rb b/test/test_puma_server_ssl.rb index 33afc080..89040353 100644 --- a/test/test_puma_server_ssl.rb +++ b/test/test_puma_server_ssl.rb @@ -22,7 +22,7 @@ class TestPumaServerSSL < Minitest::Test def setup return if DISABLE_SSL - port = 3212 + port = UniquePort.call host = "127.0.0.1" app = lambda { |env| [200, {}, [env['rack.url_scheme']]] } diff --git a/test/test_tcp_rack.rb b/test/test_tcp_rack.rb index f746c406..10ab7fe4 100644 --- a/test/test_tcp_rack.rb +++ b/test/test_tcp_rack.rb @@ -3,7 +3,7 @@ require_relative "helper" class TestTCPRack < Minitest::Test def setup - @port = 3212 + @port = UniquePort.call @host = "127.0.0.1" @events = Puma::Events.new STDOUT, STDERR