1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

Use port 0 - test_persistent.rb, test_puma_server.rb, test_puma_server_ssl.rb

add_tcp_listener and add_ssl_listener both return a TCPServer, from which
the port can be retrieved.
This commit is contained in:
MSP-Greg 2020-07-22 10:04:36 -05:00
parent 27679d02f2
commit 8ccdb2c214
No known key found for this signature in database
GPG key ID: D688DA4A77D8FA18
3 changed files with 8 additions and 15 deletions

View file

@ -23,10 +23,8 @@ class TestPersistent < Minitest::Test
[status, @headers, @body]
end
@port = UniquePort.call
@server = Puma::Server.new @simple
@server.add_tcp_listener HOST, @port
@port = (@server.add_tcp_listener HOST, 0).addr[1]
@server.max_threads = 1
@server.run

View file

@ -6,7 +6,6 @@ class TestPumaServer < Minitest::Test
parallelize_me!
def setup
@port = 0
@host = "127.0.0.1"
@ios = []
@ -24,7 +23,7 @@ class TestPumaServer < Minitest::Test
def server_run(app: @app, early_hints: false)
@server.app = app
@server.add_tcp_listener @host, @port
@port = (@server.add_tcp_listener @host, 0).addr[1]
@server.early_hints = true if early_hints
@server.run
end
@ -49,8 +48,7 @@ class TestPumaServer < Minitest::Test
end
def new_connection
port = @server.connected_ports[0]
TCPSocket.new(@host, port).tap {|sock| @ios << sock}
TCPSocket.new(@host, @port).tap {|sock| @ios << sock}
end
def test_proper_stringio_body
@ -138,8 +136,7 @@ class TestPumaServer < Minitest::Test
req = Net::HTTP::Get.new '/'
req['HOST'] = 'example.com'
port = @server.connected_ports[0]
res = Net::HTTP.start @host, port do |http|
res = Net::HTTP.start @host, @port do |http|
http.request(req)
end
@ -155,8 +152,7 @@ class TestPumaServer < Minitest::Test
req['HOST'] = "example.com"
req['X-FORWARDED-PROTO'] = "https,http"
port = @server.connected_ports[0]
res = Net::HTTP.start @host, port do |http|
res = Net::HTTP.start @host, @port do |http|
http.request(req)
end
@ -1024,7 +1020,7 @@ EOF
end
def stub_accept_nonblock(error)
@server.add_tcp_listener @host, @port
@port = (@server.add_tcp_listener @host, 0).addr[1]
io = @server.binder.ios.last
accept_old = io.method(:accept_nonblock)
accept_stub = -> do

View file

@ -47,7 +47,6 @@ class TestPumaServerSSL < Minitest::Test
# yields ctx to block, use for ctx setup & configuration
def start_server
@port = 0
@host = "127.0.0.1"
app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }
@ -68,10 +67,10 @@ class TestPumaServerSSL < Minitest::Test
@events = SSLEventsHelper.new STDOUT, STDERR
@server = Puma::Server.new app, @events
@ssl_listener = @server.add_ssl_listener @host, @port, ctx
@port = (@server.add_ssl_listener @host, 0, ctx).addr[1]
@server.run
@http = Net::HTTP.new @host, @server.connected_ports[0]
@http = Net::HTTP.new @host, @port
@http.use_ssl = true
@http.verify_mode = OpenSSL::SSL::VERIFY_NONE
end