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

Test files - more port handling

This commit is contained in:
MSP-Greg 2020-07-22 20:55:47 -05:00
parent 8ccdb2c214
commit 712d34e46f
No known key found for this signature in database
GPG key ID: D688DA4A77D8FA18
6 changed files with 19 additions and 20 deletions

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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

View file

@ -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