Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix intermittent CI issues #2739

Merged
merged 5 commits into from Oct 31, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
10 changes: 8 additions & 2 deletions lib/puma/detect.rb
Expand Up @@ -10,8 +10,10 @@ module Puma

IS_JRUBY = Object.const_defined? :JRUBY_VERSION

IS_WINDOWS = !!(RUBY_PLATFORM =~ /mswin|ming|cygwin/ ||
IS_JRUBY && RUBY_DESCRIPTION =~ /mswin/)
IS_OSX = RUBY_PLATFORM.include? 'darwin'

IS_WINDOWS = !!(RUBY_PLATFORM =~ /mswin|ming|cygwin/) ||
IS_JRUBY && RUBY_DESCRIPTION.include?('mswin')

# @version 5.2.0
IS_MRI = (RUBY_ENGINE == 'ruby' || RUBY_ENGINE.nil?)
Expand All @@ -20,6 +22,10 @@ def self.jruby?
IS_JRUBY
end

def self.osx?
IS_OSX
end

def self.windows?
IS_WINDOWS
end
Expand Down
17 changes: 10 additions & 7 deletions test/helpers/integration.rb
Expand Up @@ -105,15 +105,17 @@ def restart_server(connection, log: false)

# wait for server to say it booted
def wait_for_server_to_boot(log: false)
# OSX 10.15 seems to need a little extra time, @server.gets fails
sleep 0.2 if Puma::IS_OSX
if log
puts "Waiting for server to boot..."
begin
line = @server.gets
puts line if line && line.strip != ''
end while line !~ /Ctrl-C/
end until line.include? 'Ctrl-C'
puts "Server booted!"
else
true while @server.gets !~ /Ctrl-C/
true until @server.gets.include? 'Ctrl-C'
end
end

Expand Down Expand Up @@ -181,10 +183,10 @@ def get_worker_pids(phase = 0, size = workers)
def thread_run_refused(unix: false)
if unix
DARWIN ? [Errno::ENOENT, Errno::EPIPE, IOError] :
[Errno::ENOENT, IOError]
[IOError, Errno::ENOENT]
else
DARWIN ? [Errno::EBADF, Errno::ECONNREFUSED, Errno::EPIPE, EOFError] :
[Errno::ECONNREFUSED]
[IOError, Errno::ECONNREFUSED]
end
end

Expand Down Expand Up @@ -244,7 +246,7 @@ def hot_restart_does_not_drop_connections(num_threads: 1, total_requests: 500)
else
mutex.synchronize { replies[:unexpected_response] += 1 }
end
rescue Errno::ECONNRESET, Errno::EBADF
rescue Errno::ECONNRESET, Errno::EBADF, Errno::ENOTCONN
# connection was accepted but then closed
# client would see an empty response
# Errno::EBADF Windows may not be able to make a connection
Expand Down Expand Up @@ -306,15 +308,16 @@ def hot_restart_does_not_drop_connections(num_threads: 1, total_requests: 500)
# 5 is default thread count in Puma?
reset_max = num_threads * restart_count
assert_operator reset_max, :>=, reset, "#{msg}Expected reset_max >= reset errors"
assert_operator 30, :>=, replies[:refused], "#{msg}Too many refused connections"
else
assert_equal 0, reset, "#{msg}Expected no reset errors"
assert_equal 0, replies[:refused], "#{msg}Expected no refused connections"
end
assert_equal 0, replies[:unexpected_response], "#{msg}Unexpected response"
assert_equal 0, replies[:refused], "#{msg}Expected no refused connections"
assert_equal 0, replies[:read_timeout], "#{msg}Expected no read timeouts"

if Puma.windows?
assert_equal (num_threads * num_requests) - reset, replies[:success]
assert_equal (num_threads * num_requests) - reset - replies[:refused], replies[:success]
else
assert_equal (num_threads * num_requests), replies[:success]
end
Expand Down
2 changes: 1 addition & 1 deletion test/test_integration_cluster.rb
Expand Up @@ -523,7 +523,7 @@ def bad_exit_pids(pids)
def thread_run_pid(replies, delay, sleep_time, mutex, refused, unix: false)
begin
sleep delay
s = connect "sleep#{sleep_time}", unix: unix
s = fast_connect "sleep#{sleep_time}", unix: unix
body = read_body(s, 20)
mutex.synchronize { replies << body }
rescue Errno::ECONNRESET
Expand Down
11 changes: 10 additions & 1 deletion test/test_integration_single.rb
Expand Up @@ -184,7 +184,16 @@ def test_closed_listener
skip_unless_signal_exist? :TERM

cli_server "test/rackup/close_listeners.ru", merge_err: true
read_body connect
connection = fast_connect

if DARWIN && RUBY_VERSION < '2.5'
begin
read_body connection
rescue EOFError
end
else
read_body connection
end

begin
Timeout.timeout(5) do
Expand Down