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

Fix-up test_refork, hot_restart_does_not_drop_connections [changelog skip] (#2441)

* Fix-up test_refork, hot_restart_does_not_drop_connections

* Tests - fix two 'warning: assigned but unused variable'
This commit is contained in:
MSP-Greg 2020-10-22 14:54:57 -05:00 committed by GitHub
parent c1a98f8f22
commit 1f93fd44f5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 54 additions and 31 deletions

View file

@ -116,6 +116,35 @@ class TestIntegration < Minitest::Test
s
end
# use only if all socket writes are fast
# does not wait for a read
def fast_connect(path = nil, unix: false)
s = unix ? UNIXSocket.new(@bind_path) : TCPSocket.new(HOST, @tcp_port)
@ios_to_close << s
fast_write s, "GET /#{path} HTTP/1.1\r\n\r\n"
s
end
def fast_write(io, str)
n = 0
while true
begin
n = io.syswrite str
rescue Errno::EAGAIN, Errno::EWOULDBLOCK => e
if !IO.select(nil, [io], nil, 5)
raise e
end
retry
rescue Errno::EPIPE, SystemCallError, IOError => e
raise e
end
return if n == str.bytesize
str = str.byteslice(n..-1)
end
end
def read_body(connection, time_out = 10)
Timeout.timeout(time_out) do
loop do
@ -193,7 +222,6 @@ class TestIntegration < Minitest::Test
begin
socket = TCPSocket.new HOST, @tcp_port
fast_write socket, "POST / HTTP/1.1\r\nContent-Length: #{message.bytesize}\r\n\r\n#{message}"
true until socket.gets == "\r\n"
body = read_body(socket, 10)
if body == "Hello World"
mutex.synchronize {
@ -263,7 +291,7 @@ class TestIntegration < Minitest::Test
if Puma.windows?
# 5 is default thread count in Puma?
reset_max = num_threads > 1 ? restart_count * 5 : 5
reset_max = num_threads * restart_count
assert_operator reset_max, :>=, reset, "#{msg}Expected reset_max >= reset errors"
else
assert_equal 0, reset, "#{msg}Expected no reset errors"
@ -287,24 +315,4 @@ class TestIntegration < Minitest::Test
$debugging_info << "#{full_name}\n#{msg}\n"
end
end
def fast_write(io, str)
n = 0
while true
begin
n = io.syswrite str
rescue Errno::EAGAIN, Errno::EWOULDBLOCK => e
if !IO.select(nil, [io], nil, 5)
raise e
end
retry
rescue Errno::EPIPE, SystemCallError, IOError => e
raise e
end
return if n == str.bytesize
str = str.byteslice(n..-1)
end
end
end

View file

@ -190,15 +190,30 @@ RUBY
assert(worker_index_within_number_of_workers)
end
# use three workers to keep accepting clients
def test_refork
refork = Tempfile.new('refork')
cli_server "-w #{workers} test/rackup/sleep.ru", config: <<RUBY
fork_worker 1
on_refork {File.write('#{refork.path}', 'Reforked')}
refork = Tempfile.new 'refork'
wrkrs = 3
cli_server "-w #{wrkrs} test/rackup/hello_with_delay.ru", config: <<RUBY
fork_worker 20
on_refork { File.write '#{refork.path}', 'Reforked' }
RUBY
pids = get_worker_pids
read_body(connect('sleep1')) until refork.read == 'Reforked'
refute_includes pids, get_worker_pids(1, workers - 1)
pids = get_worker_pids 0, wrkrs
socks = []
until refork.read == 'Reforked'
socks << fast_connect
sleep 0.004
end
100.times {
socks << fast_connect
sleep 0.004
}
socks.each { |s| read_body s }
refute_includes pids, get_worker_pids(1, wrkrs - 1)
end
def test_fork_worker_spawn

View file

@ -109,7 +109,7 @@ class TestIntegrationPumactl < TestIntegration
cli_pumactl "stop", unix: true
_, status = Process.wait2(@pid)
_, _ = Process.wait2(@pid)
@server = nil
end

View file

@ -182,7 +182,7 @@ class TestPumaControlCli < TestConfigFileBase
out, _ = capture_subprocess_io do
begin
cmd.run
rescue SystemExit => e
rescue SystemExit
end
end
assert_match expected_out, out