Skip to content

Commit

Permalink
Try to fix intermittent CI issues (puma#2739)
Browse files Browse the repository at this point in the history
* TestIntegrationSingle#test_closed_listener - fix on older OSX
* detect.rb - Add OSX / darwin detection
* TestIntegration#wait_for_server_to_boot - give OSX a delay for boot
* test/helpers/integration.rb - CI fixes
* TestIntegrationCluster#thread_run_pid - try faxt_connect (no read)

Co-authored-by: Patrik Ragnarsson <patrik@starkast.net>
  • Loading branch information
2 people authored and JuanitoFatas committed Sep 9, 2022
1 parent c44609a commit 37486f3
Show file tree
Hide file tree
Showing 4 changed files with 29 additions and 11 deletions.
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

0 comments on commit 37486f3

Please sign in to comment.