2019-09-11 10:22:29 -04:00
|
|
|
require_relative "helper"
|
|
|
|
require_relative "helpers/integration"
|
|
|
|
|
|
|
|
class TestIntegrationSingle < TestIntegration
|
2020-10-13 18:36:55 -04:00
|
|
|
parallelize_me! if ::Puma.mri?
|
2019-09-19 13:37:53 -04:00
|
|
|
|
2020-10-10 19:55:11 -04:00
|
|
|
def workers ; 0 ; end
|
|
|
|
|
|
|
|
def test_hot_restart_does_not_drop_connections_threads
|
|
|
|
hot_restart_does_not_drop_connections num_threads: 5, total_requests: 1_000
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_hot_restart_does_not_drop_connections
|
|
|
|
hot_restart_does_not_drop_connections
|
|
|
|
end
|
|
|
|
|
2019-09-11 10:22:29 -04:00
|
|
|
def test_usr2_restart
|
|
|
|
skip_unless_signal_exist? :USR2
|
|
|
|
_, new_reply = restart_server_and_listen("-q test/rackup/hello.ru")
|
|
|
|
assert_equal "Hello World", new_reply
|
|
|
|
end
|
|
|
|
|
|
|
|
# It does not share environments between multiple generations, which would break Dotenv
|
|
|
|
def test_usr2_restart_restores_environment
|
|
|
|
# jruby has a bug where setting `nil` into the ENV or `delete` do not change the
|
|
|
|
# next workers ENV
|
|
|
|
skip_on :jruby
|
|
|
|
skip_unless_signal_exist? :USR2
|
|
|
|
|
|
|
|
initial_reply, new_reply = restart_server_and_listen("-q test/rackup/hello-env.ru")
|
|
|
|
|
|
|
|
assert_includes initial_reply, "Hello RAND"
|
|
|
|
assert_includes new_reply, "Hello RAND"
|
|
|
|
refute_equal initial_reply, new_reply
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_term_exit_code
|
2019-09-19 13:37:53 -04:00
|
|
|
skip_unless_signal_exist? :TERM
|
2019-09-19 09:48:16 -04:00
|
|
|
skip_on :jruby # JVM does not return correct exit code for TERM
|
2019-09-11 10:22:29 -04:00
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
cli_server "test/rackup/hello.ru"
|
|
|
|
_, status = stop_server
|
2019-09-11 10:22:29 -04:00
|
|
|
|
|
|
|
assert_equal 15, status
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_term_suppress
|
2019-09-19 13:37:53 -04:00
|
|
|
skip_unless_signal_exist? :TERM
|
2019-09-11 10:22:29 -04:00
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
cli_server "-C test/config/suppress_exception.rb test/rackup/hello.ru"
|
|
|
|
_, status = stop_server
|
2019-09-11 10:22:29 -04:00
|
|
|
|
|
|
|
assert_equal 0, status
|
|
|
|
end
|
|
|
|
|
2020-04-27 19:15:33 -04:00
|
|
|
def test_prefer_rackup_file_specified_by_cli
|
|
|
|
skip_unless_signal_exist? :TERM
|
|
|
|
|
|
|
|
cli_server "-C test/config/with_rackup_from_dsl.rb test/rackup/hello.ru"
|
2020-09-27 11:33:05 -04:00
|
|
|
reply = read_body(connect)
|
2020-05-11 00:21:24 -04:00
|
|
|
stop_server
|
2020-04-27 19:15:33 -04:00
|
|
|
|
|
|
|
assert_match("Hello World", reply)
|
|
|
|
end
|
|
|
|
|
2019-09-11 10:22:29 -04:00
|
|
|
def test_term_not_accepts_new_connections
|
2019-09-19 13:37:53 -04:00
|
|
|
skip_unless_signal_exist? :TERM
|
|
|
|
skip_on :jruby
|
2019-09-11 10:22:29 -04:00
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
cli_server 'test/rackup/sleep.ru'
|
2019-09-11 10:22:29 -04:00
|
|
|
|
2020-03-07 10:57:17 -05:00
|
|
|
_stdin, curl_stdout, _stderr, curl_wait_thread = Open3.popen3({ 'LC_ALL' => 'C' }, "curl http://#{HOST}:#{@tcp_port}/sleep10")
|
2019-09-11 10:22:29 -04:00
|
|
|
sleep 1 # ensure curl send a request
|
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
Process.kill :TERM, @pid
|
2019-09-11 10:22:29 -04:00
|
|
|
true while @server.gets !~ /Gracefully stopping/ # wait for server to begin graceful shutdown
|
|
|
|
|
|
|
|
# Invoke a request which must be rejected
|
|
|
|
_stdin, _stdout, rejected_curl_stderr, rejected_curl_wait_thread = Open3.popen3("curl #{HOST}:#{@tcp_port}")
|
|
|
|
|
|
|
|
assert nil != Process.getpgid(@server.pid) # ensure server is still running
|
2020-05-15 13:00:42 -04:00
|
|
|
assert nil != Process.getpgid(curl_wait_thread[:pid]) # ensure first curl invocation still in progress
|
2019-09-11 10:22:29 -04:00
|
|
|
|
|
|
|
curl_wait_thread.join
|
|
|
|
rejected_curl_wait_thread.join
|
|
|
|
|
|
|
|
assert_match(/Slept 10/, curl_stdout.read)
|
|
|
|
assert_match(/Connection refused/, rejected_curl_stderr.read)
|
|
|
|
|
|
|
|
Process.wait(@server.pid)
|
|
|
|
@server.close unless @server.closed?
|
|
|
|
@server = nil # prevent `#teardown` from killing already killed server
|
|
|
|
end
|
2019-09-11 12:24:53 -04:00
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
def test_int_refuse
|
|
|
|
skip_unless_signal_exist? :INT
|
2020-10-19 11:22:28 -04:00
|
|
|
skip_on :jruby # seems to intermittently lockup JRuby CI
|
2019-09-11 12:24:53 -04:00
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
cli_server 'test/rackup/hello.ru'
|
2019-09-11 12:24:53 -04:00
|
|
|
begin
|
|
|
|
sock = TCPSocket.new(HOST, @tcp_port)
|
|
|
|
sock.close
|
|
|
|
rescue => ex
|
|
|
|
fail("Port didn't open properly: #{ex.message}")
|
|
|
|
end
|
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
Process.kill :INT, @pid
|
|
|
|
Process.wait @pid
|
2019-09-11 12:24:53 -04:00
|
|
|
|
|
|
|
assert_raises(Errno::ECONNREFUSED) { TCPSocket.new(HOST, @tcp_port) }
|
|
|
|
end
|
2019-09-12 05:59:54 -04:00
|
|
|
|
|
|
|
def test_siginfo_thread_print
|
|
|
|
skip_unless_signal_exist? :INFO
|
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
cli_server 'test/rackup/hello.ru'
|
2019-09-12 05:59:54 -04:00
|
|
|
output = []
|
|
|
|
t = Thread.new { output << @server.readlines }
|
2019-09-19 13:37:53 -04:00
|
|
|
Process.kill :INFO, @pid
|
|
|
|
Process.kill :INT , @pid
|
2019-09-12 05:59:54 -04:00
|
|
|
t.join
|
|
|
|
|
2019-11-11 00:08:41 -05:00
|
|
|
assert_match "Thread: TID", output.join
|
2019-09-12 05:59:54 -04:00
|
|
|
end
|
2020-04-29 02:06:11 -04:00
|
|
|
|
|
|
|
def test_write_to_log
|
|
|
|
skip_unless_signal_exist? :TERM
|
|
|
|
|
|
|
|
suppress_output = '> /dev/null 2>&1'
|
|
|
|
|
|
|
|
cli_server '-C test/config/t1_conf.rb test/rackup/hello.ru'
|
|
|
|
|
|
|
|
system "curl http://localhost:#{@tcp_port}/ #{suppress_output}"
|
|
|
|
|
|
|
|
stop_server
|
|
|
|
|
|
|
|
log = File.read('t1-stdout')
|
|
|
|
|
|
|
|
File.unlink 't1-stdout' if File.file? 't1-stdout'
|
|
|
|
File.unlink 't1-pid' if File.file? 't1-pid'
|
|
|
|
|
|
|
|
assert_match(%r!GET / HTTP/1\.1!, log)
|
|
|
|
end
|
2020-08-27 06:30:25 -04:00
|
|
|
|
|
|
|
def test_puma_started_log_writing
|
2020-08-27 06:39:53 -04:00
|
|
|
skip_unless_signal_exist? :TERM
|
|
|
|
|
2020-08-27 06:30:25 -04:00
|
|
|
suppress_output = '> /dev/null 2>&1'
|
|
|
|
|
|
|
|
cli_server '-C test/config/t2_conf.rb test/rackup/hello.ru'
|
|
|
|
|
|
|
|
system "curl http://localhost:#{@tcp_port}/ #{suppress_output}"
|
|
|
|
|
2020-08-27 08:07:00 -04:00
|
|
|
out=`#{BASE} bin/pumactl -F test/config/t2_conf.rb status`
|
2020-08-27 06:30:25 -04:00
|
|
|
|
|
|
|
stop_server
|
|
|
|
|
|
|
|
log = File.read('t2-stdout')
|
|
|
|
|
|
|
|
File.unlink 't2-stdout' if File.file? 't2-stdout'
|
|
|
|
|
|
|
|
assert_match(%r!GET / HTTP/1\.1!, log)
|
|
|
|
assert(!File.file?("t2-pid"))
|
|
|
|
assert_equal("Puma is started\n", out)
|
|
|
|
end
|
2019-09-11 10:22:29 -04:00
|
|
|
end
|