diff --git a/test/helper.rb b/test/helper.rb index 8196652b..ddb99ee1 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -16,6 +16,7 @@ require "minitest/autorun" require "minitest/pride" require "minitest/proveit" require "minitest/stub_const" +require "net/http" require_relative "helpers/apps" Thread.abort_on_exception = true @@ -29,7 +30,6 @@ require "puma/detect" # Either takes a string to do a get request against, or a tuple of [URI, HTTP] where # HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.) def hit(uris) - require "net/http" uris.map do |u| response = if u.kind_of? String diff --git a/test/test_busy_worker.rb b/test/test_busy_worker.rb index eed31b2b..ed5b85d9 100644 --- a/test/test_busy_worker.rb +++ b/test/test_busy_worker.rb @@ -15,7 +15,7 @@ class TestBusyWorker < Minitest::Test end def new_connection - TCPSocket.new('127.0.0.1', @server.connected_ports[0]).tap {|s| @ios << s} + TCPSocket.new('127.0.0.1', @port).tap {|s| @ios << s} rescue IOError Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue retry @@ -56,7 +56,7 @@ class TestBusyWorker < Minitest::Test @server = Puma::Server.new request_handler, Puma::Events.strings, **options @server.min_threads = options[:min_threads] || 0 @server.max_threads = options[:max_threads] || 10 - @server.add_tcp_listener '127.0.0.1', 0 + @port = (@server.add_tcp_listener '127.0.0.1', 0).addr[1] @server.run end diff --git a/test/test_events.rb b/test/test_events.rb index 0a1003d7..bdc61eb4 100644 --- a/test/test_events.rb +++ b/test/test_events.rb @@ -167,10 +167,9 @@ class TestEvents < Minitest::Test events = Puma::Events.strings server = Puma::Server.new app, events - server.add_tcp_listener host, port + port = (server.add_tcp_listener host, 0).addr[1] server.run - port = server.connected_ports[0] sock = TCPSocket.new host, port path = "/" params = "a"*1024*10 diff --git a/test/test_out_of_band_server.rb b/test/test_out_of_band_server.rb index d81be898..bd537e81 100644 --- a/test/test_out_of_band_server.rb +++ b/test/test_out_of_band_server.rb @@ -19,7 +19,7 @@ class TestOutOfBandServer < Minitest::Test end def new_connection - TCPSocket.new('127.0.0.1', @server.connected_ports[0]).tap {|s| @ios << s} + TCPSocket.new('127.0.0.1', @port).tap {|s| @ios << s} rescue IOError Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue retry @@ -62,7 +62,7 @@ class TestOutOfBandServer < Minitest::Test @server = Puma::Server.new app, Puma::Events.strings, out_of_band: [oob], **options @server.min_threads = options[:min_threads] || 1 @server.max_threads = options[:max_threads] || 1 - @server.add_tcp_listener '127.0.0.1', 0 + @port = (@server.add_tcp_listener '127.0.0.1', 0).addr[1] @server.run end diff --git a/test/test_rack_server.rb b/test/test_rack_server.rb index f7d2a683..e38bb1e9 100644 --- a/test/test_rack_server.rb +++ b/test/test_rack_server.rb @@ -35,8 +35,8 @@ class TestRackServer < Minitest::Test def setup @simple = lambda { |env| [200, { "X-Header" => "Works" }, ["Hello"]] } @server = Puma::Server.new @simple - @server.add_tcp_listener "127.0.0.1", 0 - + port = (@server.add_tcp_listener "127.0.0.1", 0).addr[1] + @tcp = "http://127.0.0.1:#{port}" @stopped = false end @@ -55,7 +55,7 @@ class TestRackServer < Minitest::Test @server.run - hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test"]) + hit(["#{@tcp}/test"]) stop @@ -70,7 +70,7 @@ class TestRackServer < Minitest::Test big = "x" * (1024 * 16) - Net::HTTP.post_form URI.parse("http://127.0.0.1:#{ @server.connected_ports[0] }/test"), + Net::HTTP.post_form URI.parse("#{@tcp}/test"), { "big" => big } stop @@ -83,7 +83,7 @@ class TestRackServer < Minitest::Test @server.app = lambda { |env| input = env; @simple.call(env) } @server.run - hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test/a/b/c"]) + hit(["#{@tcp}/test/a/b/c"]) stop @@ -100,7 +100,7 @@ class TestRackServer < Minitest::Test @server.run - hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test"]) + hit(["#{@tcp}/test"]) stop @@ -116,7 +116,7 @@ class TestRackServer < Minitest::Test @server.run - hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test"]) + hit(["#{@tcp}/test"]) stop diff --git a/test/test_web_server.rb b/test/test_web_server.rb index e10eca20..9dc1093c 100644 --- a/test/test_web_server.rb +++ b/test/test_web_server.rb @@ -24,8 +24,8 @@ class WebServerTest < Minitest::Test def setup @tester = TestHandler.new @server = Puma::Server.new @tester, Puma::Events.strings - @server.add_tcp_listener "127.0.0.1", 0 - + @port = (@server.add_tcp_listener "127.0.0.1", 0).addr[1] + @tcp = "http://127.0.0.1:#{@port}" @server.run end @@ -34,14 +34,14 @@ class WebServerTest < Minitest::Test end def test_simple_server - hit(["http://127.0.0.1:#{@server.connected_ports[0]}/test"]) + hit(["#{@tcp}/test"]) assert @tester.ran_test, "Handler didn't really run" end def test_requests_count assert_equal @server.requests_count, 0 3.times do - hit(["http://127.0.0.1:#{@server.connected_ports[0]}/test"]) + hit(["#{@tcp}/test"]) end assert_equal @server.requests_count, 3 end @@ -83,7 +83,7 @@ class WebServerTest < Minitest::Test def do_test(string, chunk) # Do not use instance variables here, because it needs to be thread safe - socket = TCPSocket.new("127.0.0.1", @server.connected_ports[0]); + socket = TCPSocket.new("127.0.0.1", @port); request = StringIO.new(string) chunks_out = 0 @@ -96,7 +96,7 @@ class WebServerTest < Minitest::Test def do_test_raise(string, chunk, close_after = nil) # Do not use instance variables here, because it needs to be thread safe - socket = TCPSocket.new("127.0.0.1", @server.connected_ports[0]); + socket = TCPSocket.new("127.0.0.1", @port); request = StringIO.new(string) chunks_out = 0