1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00
puma--puma/test/test_redirect_io.rb
MSP-Greg 6729b532b9
Small test fixes - helpers/tmp_path.rb, helper.rb & test_redirect_io.rb
Currently, helpers/tmp_path.rb uses `#capture_exceptions` to run cleanup code, which is called several times for each test.
Adjusted code in it and test/helpers.rb to run once, after teardown.
This also allows asserts in teardown to work properly, see test_integration_pumactl.rb.

Also, `Tempfile.new` attaches finalizers to each object, which seemed to be intermittently bothering JRuby.
Changed to `Tempfile.create`

test_redirect_io.rb - small fix for setup and teardown.

helper.rb - changed `if ENV['CI']` conditional so that local and cloud CI both use TimeoutEveryTestCase..

Fix RuboCop in Update const.rb
2020-09-09 14:44:02 -05:00

109 lines
2.7 KiB
Ruby

require_relative "helper"
require_relative "helpers/integration"
class TestRedirectIO < TestIntegration
parallelize_me!
def setup
skip_unless_signal_exist? :HUP
super
# 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
end
def teardown
return if skipped?
super
paths = (skipped? ? [@out_file_path, @err_file_path] :
[@out_file_path, @err_file_path, @old_out_file_path, @old_err_file_path]).compact
File.unlink(*paths)
@out_file = nil
@err_file = nil
end
def test_sighup_redirects_io_single
skip_on :jruby # Server isn't coming up in CI, TODO Fix
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
skip NO_FORK_MSG unless HAS_FORK
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