mirror of
https://github.com/puma/puma.git
synced 2022-11-09 13:48:40 -05:00
make tests fast by using readpartial and not blocking read (#1322)
This commit is contained in:
parent
ddf57c822d
commit
290c22c9ad
2 changed files with 16 additions and 13 deletions
|
@ -37,7 +37,7 @@ end
|
|||
module TimeoutEveryTestCase
|
||||
def run(*)
|
||||
if ENV['CI']
|
||||
::Timeout.timeout(Puma.jruby? ? 120 : 60) { super }
|
||||
::Timeout.timeout(Puma.jruby? ? 120 : 30) { super }
|
||||
else
|
||||
super # we want to be able to use debugger
|
||||
end
|
||||
|
|
|
@ -23,7 +23,7 @@ class TestIntegration < Minitest::Test
|
|||
|
||||
def teardown
|
||||
File.unlink @state_path rescue nil
|
||||
File.unlink @bind_path rescue nil
|
||||
File.unlink @bind_path rescue nil
|
||||
File.unlink @control_path rescue nil
|
||||
|
||||
@wait.close
|
||||
|
@ -52,9 +52,9 @@ class TestIntegration < Minitest::Test
|
|||
def restart_server_and_listen(argv)
|
||||
server(argv)
|
||||
s = connect
|
||||
initial_reply = s.read
|
||||
initial_reply = read_body(s)
|
||||
restart_server(s)
|
||||
[initial_reply, connect.read]
|
||||
[initial_reply, read_body(connect)]
|
||||
end
|
||||
|
||||
def signal(which)
|
||||
|
@ -69,16 +69,8 @@ class TestIntegration < Minitest::Test
|
|||
def restart_server(connection)
|
||||
signal :USR2
|
||||
|
||||
sleep 1
|
||||
|
||||
connection.write "GET / HTTP/1.1\r\n\r\n" # trigger it to start by sending a new request
|
||||
|
||||
assert_raises Errno::ECONNRESET do
|
||||
Timeout.timeout(2) do
|
||||
raise Errno::ECONNRESET unless connection.read(2)
|
||||
end
|
||||
end
|
||||
|
||||
wait_for_server_to_boot
|
||||
end
|
||||
|
||||
|
@ -93,6 +85,17 @@ class TestIntegration < Minitest::Test
|
|||
true while @server.gets !~ /Ctrl-C/ # wait for server to say it booted
|
||||
end
|
||||
|
||||
def read_body(connection)
|
||||
Timeout.timeout(10) do
|
||||
loop do
|
||||
response = connection.readpartial(1024)
|
||||
body = response.split("\r\n\r\n", 2).last
|
||||
return body if body && !body.empty?
|
||||
sleep 0.01
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
def test_stop_via_pumactl
|
||||
skip if Puma.jruby? || Puma.windows?
|
||||
|
||||
|
@ -115,7 +118,7 @@ class TestIntegration < Minitest::Test
|
|||
|
||||
s = UNIXSocket.new @bind_path
|
||||
s << "GET / HTTP/1.0\r\n\r\n"
|
||||
assert_equal "Hello World", s.read.split("\r\n").last
|
||||
assert_equal "Hello World", read_body(s)
|
||||
|
||||
sout = StringIO.new
|
||||
|
||||
|
|
Loading…
Reference in a new issue