2020-03-10 19:22:58 -04:00
|
|
|
require_relative "helper"
|
|
|
|
require_relative "helpers/integration"
|
|
|
|
|
|
|
|
class TestRedirectIO < TestIntegration
|
|
|
|
parallelize_me!
|
|
|
|
|
|
|
|
def setup
|
2020-09-08 19:27:58 -04:00
|
|
|
skip_unless_signal_exist? :HUP
|
2020-03-10 19:22:58 -04:00
|
|
|
super
|
|
|
|
|
2020-03-24 17:13:31 -04:00
|
|
|
# Keep the Tempfile instances alive to avoid being GC'd
|
|
|
|
@out_file = Tempfile.new('puma-out')
|
|
|
|
@err_file = Tempfile.new('puma-err')
|
|
|
|
@out_file_path = @out_file.path
|
|
|
|
@err_file_path = @err_file.path
|
2020-03-10 19:22:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def teardown
|
2020-09-08 19:27:58 -04:00
|
|
|
return if skipped?
|
2020-03-10 19:22:58 -04:00
|
|
|
super
|
|
|
|
|
2020-05-15 00:17:41 -04:00
|
|
|
paths = (skipped? ? [@out_file_path, @err_file_path] :
|
|
|
|
[@out_file_path, @err_file_path, @old_out_file_path, @old_err_file_path]).compact
|
|
|
|
|
2020-03-10 19:22:58 -04:00
|
|
|
File.unlink(*paths)
|
2020-03-24 17:13:31 -04:00
|
|
|
@out_file = nil
|
|
|
|
@err_file = nil
|
2020-03-10 19:22:58 -04:00
|
|
|
end
|
|
|
|
|
|
|
|
def test_sighup_redirects_io_single
|
2021-03-15 10:10:43 -04:00
|
|
|
skip_if :jruby # Server isn't coming up in CI, TODO Fix
|
2020-03-10 19:22:58 -04:00
|
|
|
|
|
|
|
cli_args = [
|
|
|
|
'--redirect-stdout', @out_file_path,
|
|
|
|
'--redirect-stderr', @err_file_path,
|
|
|
|
'test/rackup/hello.ru'
|
|
|
|
]
|
|
|
|
cli_server cli_args.join ' '
|
|
|
|
|
|
|
|
wait_until_file_has_content @out_file_path
|
|
|
|
assert_match 'puma startup', File.read(@out_file_path)
|
|
|
|
|
|
|
|
wait_until_file_has_content @err_file_path
|
|
|
|
assert_match 'puma startup', File.read(@err_file_path)
|
|
|
|
|
|
|
|
log_rotate_output_files
|
|
|
|
|
|
|
|
Process.kill :HUP, @server.pid
|
|
|
|
|
|
|
|
wait_until_file_has_content @out_file_path
|
|
|
|
assert_match 'puma startup', File.read(@out_file_path)
|
|
|
|
|
|
|
|
wait_until_file_has_content @err_file_path
|
|
|
|
assert_match 'puma startup', File.read(@err_file_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_sighup_redirects_io_cluster
|
2021-03-15 10:10:43 -04:00
|
|
|
skip_unless :fork
|
2020-03-10 19:22:58 -04:00
|
|
|
|
|
|
|
cli_args = [
|
|
|
|
'-w', '1',
|
|
|
|
'--redirect-stdout', @out_file_path,
|
|
|
|
'--redirect-stderr', @err_file_path,
|
|
|
|
'test/rackup/hello.ru'
|
|
|
|
]
|
|
|
|
cli_server cli_args.join ' '
|
|
|
|
|
|
|
|
wait_until_file_has_content @out_file_path
|
|
|
|
assert_match 'puma startup', File.read(@out_file_path)
|
|
|
|
|
|
|
|
wait_until_file_has_content @err_file_path
|
|
|
|
assert_match 'puma startup', File.read(@err_file_path)
|
|
|
|
|
|
|
|
log_rotate_output_files
|
|
|
|
|
|
|
|
Process.kill :HUP, @server.pid
|
|
|
|
|
|
|
|
wait_until_file_has_content @out_file_path
|
|
|
|
assert_match 'puma startup', File.read(@out_file_path)
|
|
|
|
|
|
|
|
wait_until_file_has_content @err_file_path
|
|
|
|
assert_match 'puma startup', File.read(@err_file_path)
|
|
|
|
end
|
|
|
|
|
|
|
|
private
|
|
|
|
|
|
|
|
def log_rotate_output_files
|
|
|
|
# rename both files to .old
|
|
|
|
@old_out_file_path = "#{@out_file_path}.old"
|
|
|
|
@old_err_file_path = "#{@err_file_path}.old"
|
|
|
|
File.rename @out_file_path, @old_out_file_path
|
|
|
|
File.rename @err_file_path, @old_err_file_path
|
|
|
|
|
|
|
|
File.new(@out_file_path, File::CREAT).close
|
|
|
|
File.new(@err_file_path, File::CREAT).close
|
|
|
|
end
|
|
|
|
|
|
|
|
def wait_until_file_has_content(path)
|
|
|
|
File.open(path) do |file|
|
|
|
|
begin
|
|
|
|
file.read_nonblock 1
|
|
|
|
file.seek 0
|
|
|
|
rescue EOFError
|
|
|
|
sleep 0.1
|
|
|
|
retry
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|