From 37486f3007b2a88801d72ba4572cea30cde09e64 Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Sun, 31 Oct 2021 06:06:58 -0500 Subject: [PATCH] Try to fix intermittent CI issues (#2739) * 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 --- lib/puma/detect.rb | 10 ++++++++-- test/helpers/integration.rb | 17 ++++++++++------- test/test_integration_cluster.rb | 2 +- test/test_integration_single.rb | 11 ++++++++++- 4 files changed, 29 insertions(+), 11 deletions(-) diff --git a/lib/puma/detect.rb b/lib/puma/detect.rb index c85a359704..565ed00c45 100644 --- a/lib/puma/detect.rb +++ b/lib/puma/detect.rb @@ -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?) @@ -20,6 +22,10 @@ def self.jruby? IS_JRUBY end + def self.osx? + IS_OSX + end + def self.windows? IS_WINDOWS end diff --git a/test/helpers/integration.rb b/test/helpers/integration.rb index 49a48e318e..931ef1d2a2 100644 --- a/test/helpers/integration.rb +++ b/test/helpers/integration.rb @@ -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 @@ -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 @@ -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 @@ -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 diff --git a/test/test_integration_cluster.rb b/test/test_integration_cluster.rb index 33bbf6f592..374bfbbc5d 100644 --- a/test/test_integration_cluster.rb +++ b/test/test_integration_cluster.rb @@ -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 diff --git a/test/test_integration_single.rb b/test/test_integration_single.rb index f931e1a3cb..fd930fe68b 100644 --- a/test/test_integration_single.rb +++ b/test/test_integration_single.rb @@ -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