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/pride"
require "minitest/proveit" require "minitest/proveit"
require "minitest/stub_const" require "minitest/stub_const"
require "net/http"
require_relative "helpers/apps" require_relative "helpers/apps"
Thread.abort_on_exception = true 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 # 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.) # HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris) def hit(uris)
require "net/http"
uris.map do |u| uris.map do |u|
response = response =
if u.kind_of? String if u.kind_of? String

View file

@ -15,7 +15,7 @@ class TestBusyWorker < Minitest::Test
end end
def new_connection 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 rescue IOError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
retry retry
@ -56,7 +56,7 @@ class TestBusyWorker < Minitest::Test
@server = Puma::Server.new request_handler, Puma::Events.strings, **options @server = Puma::Server.new request_handler, Puma::Events.strings, **options
@server.min_threads = options[:min_threads] || 0 @server.min_threads = options[:min_threads] || 0
@server.max_threads = options[:max_threads] || 10 @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 @server.run
end end

View file

@ -167,10 +167,9 @@ class TestEvents < Minitest::Test
events = Puma::Events.strings events = Puma::Events.strings
server = Puma::Server.new app, events server = Puma::Server.new app, events
server.add_tcp_listener host, port port = (server.add_tcp_listener host, 0).addr[1]
server.run server.run
port = server.connected_ports[0]
sock = TCPSocket.new host, port sock = TCPSocket.new host, port
path = "/" path = "/"
params = "a"*1024*10 params = "a"*1024*10

View file

@ -19,7 +19,7 @@ class TestOutOfBandServer < Minitest::Test
end end
def new_connection 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 rescue IOError
Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue Thread.current.purge_interrupt_queue if Thread.current.respond_to? :purge_interrupt_queue
retry retry
@ -62,7 +62,7 @@ class TestOutOfBandServer < Minitest::Test
@server = Puma::Server.new app, Puma::Events.strings, out_of_band: [oob], **options @server = Puma::Server.new app, Puma::Events.strings, out_of_band: [oob], **options
@server.min_threads = options[:min_threads] || 1 @server.min_threads = options[:min_threads] || 1
@server.max_threads = options[:max_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 @server.run
end end

View file

@ -35,8 +35,8 @@ class TestRackServer < Minitest::Test
def setup def setup
@simple = lambda { |env| [200, { "X-Header" => "Works" }, ["Hello"]] } @simple = lambda { |env| [200, { "X-Header" => "Works" }, ["Hello"]] }
@server = Puma::Server.new @simple @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 @stopped = false
end end
@ -55,7 +55,7 @@ class TestRackServer < Minitest::Test
@server.run @server.run
hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test"]) hit(["#{@tcp}/test"])
stop stop
@ -70,7 +70,7 @@ class TestRackServer < Minitest::Test
big = "x" * (1024 * 16) 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 } { "big" => big }
stop stop
@ -83,7 +83,7 @@ class TestRackServer < Minitest::Test
@server.app = lambda { |env| input = env; @simple.call(env) } @server.app = lambda { |env| input = env; @simple.call(env) }
@server.run @server.run
hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test/a/b/c"]) hit(["#{@tcp}/test/a/b/c"])
stop stop
@ -100,7 +100,7 @@ class TestRackServer < Minitest::Test
@server.run @server.run
hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test"]) hit(["#{@tcp}/test"])
stop stop
@ -116,7 +116,7 @@ class TestRackServer < Minitest::Test
@server.run @server.run
hit(["http://127.0.0.1:#{ @server.connected_ports[0] }/test"]) hit(["#{@tcp}/test"])
stop stop

View file

@ -24,8 +24,8 @@ class WebServerTest < Minitest::Test
def setup def setup
@tester = TestHandler.new @tester = TestHandler.new
@server = Puma::Server.new @tester, Puma::Events.strings @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 @server.run
end end
@ -34,14 +34,14 @@ class WebServerTest < Minitest::Test
end end
def test_simple_server 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" assert @tester.ran_test, "Handler didn't really run"
end end
def test_requests_count def test_requests_count
assert_equal @server.requests_count, 0 assert_equal @server.requests_count, 0
3.times do 3.times do
hit(["http://127.0.0.1:#{@server.connected_ports[0]}/test"]) hit(["#{@tcp}/test"])
end end
assert_equal @server.requests_count, 3 assert_equal @server.requests_count, 3
end end
@ -83,7 +83,7 @@ class WebServerTest < Minitest::Test
def do_test(string, chunk) def do_test(string, chunk)
# Do not use instance variables here, because it needs to be thread safe # 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) request = StringIO.new(string)
chunks_out = 0 chunks_out = 0
@ -96,7 +96,7 @@ class WebServerTest < Minitest::Test
def do_test_raise(string, chunk, close_after = nil) def do_test_raise(string, chunk, close_after = nil)
# Do not use instance variables here, because it needs to be thread safe # 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) request = StringIO.new(string)
chunks_out = 0 chunks_out = 0