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

Fix rack handler test to use port 0

This commit is contained in:
schneems 2016-02-04 16:36:24 -06:00
parent 36711207e8
commit 023c0c8ecd
2 changed files with 14 additions and 10 deletions

View file

@ -176,6 +176,10 @@ module Puma
@runner.stop
end
def connected_port
@binder.connected_port
end
def restart
@status = :restart
@runner.restart

View file

@ -22,33 +22,33 @@ class TestPathHandler < Test::Unit::TestCase
end
def in_handler(app, options = {})
options[:Port] ||= 9998
@server = nil
options[:Port] ||= 0
@launcher = nil
thread = Thread.new do
Rack::Handler::Puma.run(app, options) do |s|
@server = s
Rack::Handler::Puma.run(app, options) do |s, p|
@launcher = s
end
end
thread.abort_on_exception = true
# Wait for server to boot
# Wait for launcher to boot
Timeout.timeout(10) do
until @server
until @launcher
sleep 1
end
end
sleep 1
yield @server
yield @launcher
ensure
@server.stop if @server
@launcher.stop if @launcher
thread.join if thread
end
def test_handler_boots
in_handler(app) do |server|
hit(["http://0.0.0.0:9998/test"])
in_handler(app) do |launcher|
hit(["http://0.0.0.0:#{ launcher.connected_port }/test"])
assert_equal("/test", @input["PATH_INFO"])
end
end