From a0cab5d837278e55afabeb8b033ef0d58a63e17e Mon Sep 17 00:00:00 2001 From: MSP-Greg Date: Tue, 7 Sep 2021 17:02:00 -0500 Subject: [PATCH] Test Fixes (#2693) 1. Move SSLEventsHelper to test/helper.rb, fixes `warning: method redefined` 2. Collapse 'Debugging Info' in Actions log 3. Fix 'shadowed cariable' warning --- test/helper.rb | 31 ++++++++++++++++++++++----- test/test_puma_localhost_authority.rb | 11 ---------- test/test_puma_server_ssl.rb | 13 +---------- 3 files changed, 27 insertions(+), 28 deletions(-) diff --git a/test/helper.rb b/test/helper.rb index 7107db1a..635df85d 100644 --- a/test/helper.rb +++ b/test/helper.rb @@ -27,6 +27,21 @@ $debugging_hold = false # needed for TestCLI#test_control_clustered require "puma" require "puma/detect" +# used in various ssl test files, see test_puma_server_ssl.rb and +# test_puma_localhost_authority.rb +if Puma::HAS_SSL + require "puma/events" + class SSLEventsHelper < ::Puma::Events + attr_accessor :addr, :cert, :error + + def ssl_error(error, ssl_socket) + self.error = error + self.addr = ssl_socket.peeraddr.last rescue "" + self.cert = ssl_socket.peercert + end + end +end + # Either takes a string to do a get request against, or a tuple of [URI, HTTP] where # HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.) def hit(uris) @@ -171,8 +186,14 @@ Minitest.after_run do unless $debugging_hold out = $debugging_info.strip unless out.empty? - puts "", " Debugging Info".rjust(75, '-'), - out, '-' * 75, "" + dash = "\u2500" + wid = ENV['GITHUB_ACTIONS'] ? 88 : 90 + txt = " Debugging Info #{dash * 2}".rjust wid, dash + if ENV['GITHUB_ACTIONS'] + puts "", "##[group]#{txt}", out, dash * wid, '', '::[endgroup]' + else + puts "", txt, out, dash * wid, '' + end end end end @@ -198,9 +219,9 @@ module AggregatedResults hsh_s.each { |k,v| io.puts " #{k} #{dash * 2}".rjust 90, dash hsh_1 = v.group_by { |i| i.first.first } - hsh_1.each { |k,v| - io.puts " #{k[/\/test\/(.*)/,1]}" - v.each { |item| + hsh_1.each { |k1,v1| + io.puts " #{k1[/\/test\/(.*)/,1]}" + v1.each { |item| num += 1 io.puts format(" %3s %-5s #{item[1]} #{item[2]}", "#{num})", ":#{item[0][1]}") } diff --git a/test/test_puma_localhost_authority.rb b/test/test_puma_localhost_authority.rb index 24d2ab19..8599980b 100644 --- a/test/test_puma_localhost_authority.rb +++ b/test/test_puma_localhost_authority.rb @@ -7,19 +7,8 @@ require "localhost/authority" if ::Puma::HAS_SSL && !Puma::IS_JRUBY require "puma/minissl" - require "puma/events" require "net/http" - class SSLEventsHelper < ::Puma::Events - attr_accessor :addr, :cert, :error - - def ssl_error(error, ssl_socket) - self.error = error - self.addr = ssl_socket.peeraddr.last rescue "" - self.cert = ssl_socket.peercert - end - end - # net/http (loaded in helper) does not necessarily load OpenSSL require "openssl" unless Object.const_defined? :OpenSSL end diff --git a/test/test_puma_server_ssl.rb b/test/test_puma_server_ssl.rb index e42b663c..a3e843f5 100644 --- a/test/test_puma_server_ssl.rb +++ b/test/test_puma_server_ssl.rb @@ -6,19 +6,8 @@ require_relative "helper" if ::Puma::HAS_SSL require "puma/minissl" - require "puma/events" require "net/http" - class SSLEventsHelper < ::Puma::Events - attr_accessor :addr, :cert, :error - - def ssl_error(error, ssl_socket) - self.error = error - self.addr = ssl_socket.peeraddr.last rescue "" - self.cert = ssl_socket.peercert - end - end - # net/http (loaded in helper) does not necessarily load OpenSSL require "openssl" unless Object.const_defined? :OpenSSL if Puma::IS_JRUBY @@ -217,7 +206,7 @@ class TestPumaServerSSL < Minitest::Test tcp = Thread.new do req_http = Net::HTTP::Get.new "/", {} # Net::ReadTimeout - TruffleRuby - assert_raises(Errno::ECONNREFUSED, EOFError, Net::ReadTimeout) do + assert_raises(Errno::ECONNREFUSED, EOFError, Net::ReadTimeout, Net::OpenTimeout) do http.start.request(req_http) { |rep| body_http = rep.body } end end