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
Benoit Daloze 0b737cce42
Run tests on TruffleRuby, all tests pass now (#2198)
* Support skip_on :truffleruby

* Remove unused variable declaration

* Properly skip tests which need fork

* Improve NO_FORK_MSG

* Keep the Tempfile instances alive in test_redirect_io.rb

* Otherwise they could GC in the middle of the test, and the files could
  then be deleted.

* Use a better way to find a free port

* Read directly from the socket in #read_and_drop

* There is no point to decode the bytes since we are closing the socket
  in Puma::MiniSSL::Socket#close.
* Also, calling #engine_read_all might cause further SSL errors, which
  could hide the first SSL error. This notably happens in
  TestPumaServerSSLClient#test_verify_fail_if_no_client_cert
  if the server is faster than the client. The error in that case is
  "System error: Success - 0 (Puma::MiniSSL::SSLError)" which is not
  actually an error, but there is also nothing to read further from SSL.

* TruffleRuby should pass the CI now, remove from allowed failures

* Use a timeout of 120 for all non-MRI implementations

* 60 doesn't seem enough in CI for TestThreadPool#test_trim on TruffleRuby.

* Fix check for cluster mode in integration tests

* Improve integration tests to fail more clearly if the pid file does not exist

* Make integration tests more robust

* Add skips for unreliable or racy tests

* Add ChangeLog entry

* No need to run RuboCop on non-MRI implementations

* This should speed up CI a bit for those jobs.
2020-03-25 06:13:31 +09:00

107 lines
2.7 KiB
Ruby

require_relative "helper"
require_relative "helpers/integration"
class TestRedirectIO < TestIntegration
parallelize_me!
def setup
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
super
paths = [@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
skip_unless_signal_exist? :HUP
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
skip_unless_signal_exist? :HUP
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