Skip to content

Commit

Permalink
Update test_integration files per PR puma#1956
Browse files Browse the repository at this point in the history
test_integration_cluster.rb

Request handling during server TERM - two tests

`#test_term_closes_listeners_tcp`
`#test_term_closes_listeners_unix`

using `#term_closes_listeners`

Send requests 10 per second.  Send 10, then :TERM server, then send another 30.
No more than 10 should throw Errno::ECONNRESET.

Request handling during phased restart - two tests

`#test_usr1_all_respond_tcp`
`#test_usr1_all_respond_unix`

using `#usr1_all_respond`

Send requests 1 per second.  Send 1, then :USR1 server, then send another 24.
All should be responded to, and at least three workers should be used

Stuck worker tests - two tests

`#test_stuck_external_term_spawn`
Tests whether externally TERM'd 'stuck' workers are proper re-spawned.

`#test_stuck_phased_restart`
Tests whether 'stuck' workers are properly shutdown during phased-restart.

helper files/methods changes

1. helper file changes to allow binding to TCP or UNIX, see kwarg unix:
2. Skip on Windows for signal TERM
  • Loading branch information
MSP-Greg committed Sep 13, 2019
1 parent 1cff081 commit 5b0fb04
Show file tree
Hide file tree
Showing 7 changed files with 208 additions and 151 deletions.
1 change: 1 addition & 0 deletions test/config/worker_shutdown_timeout_2.rb
@@ -0,0 +1 @@
worker_shutdown_timeout 2
6 changes: 4 additions & 2 deletions test/helper.rb
Expand Up @@ -84,10 +84,12 @@ module TestSkips
UNIX_SKT_EXIST = Object.const_defined? :UNIXSocket
UNIX_SKT_MSG = "UnixSockets aren't available on the #{RUBY_PLATFORM} platform"

SIGNAL_LIST = Signal.list.keys.map(&:to_sym) - (Puma.windows? ? [:TERM] : [])

# usage: skip_unless_signal_exist? :USR2
def skip_unless_signal_exist?(sig, bt: caller)
signal = sig.to_s
unless Signal.list.key? signal
signal = sig.to_s.sub(/\ASIG/, '').to_sym
unless SIGNAL_LIST.include? signal
skip "Signal #{signal} isn't available on the #{RUBY_PLATFORM} platform", bt
end
end
Expand Down
22 changes: 14 additions & 8 deletions test/helpers/integration.rb
Expand Up @@ -15,6 +15,7 @@ class TestIntegration < Minitest::Test

def setup
@ios_to_close = []
@bind_path = "test/#{name}_server.sock"
end

def teardown
Expand All @@ -36,26 +37,31 @@ def teardown
io.close if io.is_a?(IO) && !io.closed?
io = nil
end
File.unlink(@bind_path) rescue nil
end

private

def cli_server(argv, bind = nil)
if bind
cmd = "#{BASE} bin/puma -b #{bind} #{argv}"
def cli_server(argv, unix: false)
if unix
cmd = "#{BASE} bin/puma -b unix://#{@bind_path} #{argv}"
else
@tcp_port = UniquePort.call
cmd = "#{BASE} bin/puma -b tcp://#{HOST}:#{@tcp_port} #{argv}"
end
@server = IO.popen(cmd, "r")
wait_for_server_to_boot
@pid = @server.pid
@server
end

def send_term_to_server(pid)
Process.kill(:TERM, pid)
def stop_server(pid = @pid, signal: :TERM)
Process.kill signal, pid
sleep 1
Process.wait2(pid)
begin
Process.wait2 pid
rescue Errno::ECHILD
end
end

def restart_server_and_listen(argv)
Expand All @@ -77,8 +83,8 @@ def wait_for_server_to_boot
true while @server.gets !~ /Ctrl-C/ # wait for server to say it booted
end

def connect(path = nil)
s = TCPSocket.new HOST, @tcp_port
def connect(path = nil, unix: false)
s = unix ? UNIXSocket.new(@bind_path) : TCPSocket.new(HOST, @tcp_port)
@ios_to_close << s
s << "GET /#{path} HTTP/1.1\r\n\r\n"
true until s.gets == "\r\n"
Expand Down
8 changes: 8 additions & 0 deletions test/rackup/sleep_pid.ru
@@ -0,0 +1,8 @@
# call with "GET /sleep<d> HTTP/1.1\r\n\r\n", where <d> is the number of
# seconds to sleep, returns process pid

run lambda { |env|
dly = (env['REQUEST_PATH'][/\/sleep(\d+)/,1] || '0').to_i
sleep dly
[200, {"Content-Type" => "text/plain"}, ["Slept #{dly} #{Process.pid}"]]
}

0 comments on commit 5b0fb04

Please sign in to comment.