1
0
Fork 0
mirror of https://github.com/puma/puma.git synced 2022-11-09 13:48:40 -05:00

[CI] misc updates to test files (#2979)

* [CI] test/helper.rb - sort debug output by test

* [CI] test/test_puma_server_ssl.rb - remove tap call

* [CI] test/helpers/integration.rb - fixup hot_restart_does_not_drop_connections, may be pointless with CI variances
This commit is contained in:
MSP-Greg 2022-09-30 14:55:12 -05:00 committed by GitHub
parent 9770678f17
commit 838c136aeb
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 22 additions and 15 deletions

View file

@ -21,7 +21,7 @@ require_relative "helpers/apps"
Thread.abort_on_exception = true Thread.abort_on_exception = true
$debugging_info = +'' $debugging_info = []
$debugging_hold = false # needed for TestCLI#test_control_clustered $debugging_hold = false # needed for TestCLI#test_control_clustered
$test_case_timeout = ENV.fetch("TEST_CASE_TIMEOUT") do $test_case_timeout = ENV.fetch("TEST_CASE_TIMEOUT") do
RUBY_ENGINE == "ruby" ? 45 : 60 RUBY_ENGINE == "ruby" ? 45 : 60
@ -197,7 +197,8 @@ end
Minitest.after_run do Minitest.after_run do
# needed for TestCLI#test_control_clustered # needed for TestCLI#test_control_clustered
if !$debugging_hold && ENV['PUMA_TEST_DEBUG'] if !$debugging_hold && ENV['PUMA_TEST_DEBUG']
out = $debugging_info.strip $debugging_info.sort!
out = $debugging_info.join.strip
unless out.empty? unless out.empty?
dash = "\u2500" dash = "\u2500"
wid = ENV['GITHUB_ACTIONS'] ? 88 : 90 wid = ENV['GITHUB_ACTIONS'] ? 88 : 90

View file

@ -339,9 +339,14 @@ class TestIntegration < Minitest::Test
num_threads.times do |thread| num_threads.times do |thread|
client_threads << Thread.new do client_threads << Thread.new do
num_requests.times do |req_num| num_requests.times do |req_num|
begin
begin begin
socket = TCPSocket.new HOST, @tcp_port socket = TCPSocket.new HOST, @tcp_port
fast_write socket, "POST / HTTP/1.1\r\nContent-Length: #{message.bytesize}\r\n\r\n#{message}" fast_write socket, "POST / HTTP/1.1\r\nContent-Length: #{message.bytesize}\r\n\r\n#{message}"
rescue => e
replies[:write_error] += 1
raise e
end
body = read_body(socket, 10) body = read_body(socket, 10)
if body == "Hello World" if body == "Hello World"
mutex.synchronize { mutex.synchronize {
@ -377,7 +382,7 @@ class TestIntegration < Minitest::Test
run = true run = true
restart_thread = Thread.new do restart_thread = Thread.new do
sleep 0.30 # let some connections in before 1st restart sleep 0.2 # let some connections in before 1st restart
while run while run
if Puma.windows? if Puma.windows?
cli_pumactl 'restart' cli_pumactl 'restart'
@ -387,7 +392,7 @@ class TestIntegration < Minitest::Test
sleep 0.5 sleep 0.5
wait_for_server_to_boot wait_for_server_to_boot
restart_count += 1 restart_count += 1
sleep(Puma.windows? ? 2.0 : 1.0) sleep(Puma.windows? ? 2.0 : 0.5)
end end
end end
@ -410,22 +415,24 @@ class TestIntegration < Minitest::Test
msg << " %4d success after restart\n" % replies.fetch(:restart,0) msg << " %4d success after restart\n" % replies.fetch(:restart,0)
msg << " %4d restart count\n" % restart_count msg << " %4d restart count\n" % restart_count
refused = replies[:refused]
reset = replies[:reset] reset = replies[:reset]
if Puma.windows? if Puma.windows?
# 5 is default thread count in Puma? # 5 is default thread count in Puma?
reset_max = num_threads * restart_count reset_max = num_threads * restart_count
assert_operator reset_max, :>=, reset, "#{msg}Expected reset_max >= reset errors" assert_operator reset_max, :>=, reset, "#{msg}Expected reset_max >= reset errors"
assert_operator 40, :>=, replies[:refused], "#{msg}Too many refused connections" assert_operator 40, :>=, refused, "#{msg}Too many refused connections"
else else
assert_equal 0, reset, "#{msg}Expected no reset errors" assert_equal 0, reset, "#{msg}Expected no reset errors"
assert_equal 0, replies[:refused], "#{msg}Expected no refused connections" max_refused = (0.001 * replies.fetch(:success,0)).round
assert_operator max_refused, :>=, refused, "#{msg}Expected no than #{max_refused} refused connections"
end end
assert_equal 0, replies[:unexpected_response], "#{msg}Unexpected response" assert_equal 0, replies[:unexpected_response], "#{msg}Unexpected response"
assert_equal 0, replies[:read_timeout], "#{msg}Expected no read timeouts" assert_equal 0, replies[:read_timeout], "#{msg}Expected no read timeouts"
if Puma.windows? if Puma.windows?
assert_equal (num_threads * num_requests) - reset - replies[:refused], replies[:success] assert_equal (num_threads * num_requests) - reset - refused, replies[:success]
else else
assert_equal (num_threads * num_requests), replies[:success] assert_equal (num_threads * num_requests), replies[:success]
end end
@ -433,7 +440,7 @@ class TestIntegration < Minitest::Test
ensure ensure
return if skipped return if skipped
if passed? if passed?
msg = " restart_count #{restart_count}, reset #{reset}, success after restart #{replies[:restart]}" msg = " #{restart_count} restarts, #{reset} resets, #{refused} refused, #{replies[:restart]} success after restart, #{replies[:write_error]} write error"
$debugging_info << "#{full_name}\n#{msg}\n" $debugging_info << "#{full_name}\n#{msg}\n"
else else
client_threads.each { |thr| thr.kill if thr.is_a? Thread } client_threads.each { |thr| thr.kill if thr.is_a? Thread }

View file

@ -513,10 +513,9 @@ class TestPumaServerSSLWithCertPemAndKeyPem < Minitest::Test
def test_server_ssl_with_cert_pem_and_key_pem def test_server_ssl_with_cert_pem_and_key_pem
host = "localhost" host = "localhost"
port = 0 port = 0
ctx = Puma::MiniSSL::Context.new.tap { |ctx| ctx = Puma::MiniSSL::Context.new
ctx.cert_pem = File.read("#{CERT_PATH}/server.crt") ctx.cert_pem = File.read "#{CERT_PATH}/server.crt"
ctx.key_pem = File.read("#{CERT_PATH}/server.key") ctx.key_pem = File.read "#{CERT_PATH}/server.key"
}
app = lambda { |env| [200, {}, [env['rack.url_scheme']]] } app = lambda { |env| [200, {}, [env['rack.url_scheme']]] }
log_writer = SSLLogWriterHelper.new STDOUT, STDERR log_writer = SSLLogWriterHelper.new STDOUT, STDERR