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

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
This commit is contained in:
MSP-Greg 2021-09-07 17:02:00 -05:00 committed by GitHub
parent 12acfb3a1d
commit a0cab5d837
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 27 additions and 28 deletions

View file

@ -27,6 +27,21 @@ $debugging_hold = false # needed for TestCLI#test_control_clustered
require "puma" require "puma"
require "puma/detect" 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 "<unknown>"
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 # 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.) # HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris) def hit(uris)
@ -171,8 +186,14 @@ Minitest.after_run do
unless $debugging_hold unless $debugging_hold
out = $debugging_info.strip out = $debugging_info.strip
unless out.empty? unless out.empty?
puts "", " Debugging Info".rjust(75, '-'), dash = "\u2500"
out, '-' * 75, "" 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 end
end end
@ -198,9 +219,9 @@ module AggregatedResults
hsh_s.each { |k,v| hsh_s.each { |k,v|
io.puts " #{k} #{dash * 2}".rjust 90, dash io.puts " #{k} #{dash * 2}".rjust 90, dash
hsh_1 = v.group_by { |i| i.first.first } hsh_1 = v.group_by { |i| i.first.first }
hsh_1.each { |k,v| hsh_1.each { |k1,v1|
io.puts " #{k[/\/test\/(.*)/,1]}" io.puts " #{k1[/\/test\/(.*)/,1]}"
v.each { |item| v1.each { |item|
num += 1 num += 1
io.puts format(" %3s %-5s #{item[1]} #{item[2]}", "#{num})", ":#{item[0][1]}") io.puts format(" %3s %-5s #{item[1]} #{item[2]}", "#{num})", ":#{item[0][1]}")
} }

View file

@ -7,19 +7,8 @@ require "localhost/authority"
if ::Puma::HAS_SSL && !Puma::IS_JRUBY if ::Puma::HAS_SSL && !Puma::IS_JRUBY
require "puma/minissl" require "puma/minissl"
require "puma/events"
require "net/http" 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 "<unknown>"
self.cert = ssl_socket.peercert
end
end
# net/http (loaded in helper) does not necessarily load OpenSSL # net/http (loaded in helper) does not necessarily load OpenSSL
require "openssl" unless Object.const_defined? :OpenSSL require "openssl" unless Object.const_defined? :OpenSSL
end end

View file

@ -6,19 +6,8 @@ require_relative "helper"
if ::Puma::HAS_SSL if ::Puma::HAS_SSL
require "puma/minissl" require "puma/minissl"
require "puma/events"
require "net/http" 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 "<unknown>"
self.cert = ssl_socket.peercert
end
end
# net/http (loaded in helper) does not necessarily load OpenSSL # net/http (loaded in helper) does not necessarily load OpenSSL
require "openssl" unless Object.const_defined? :OpenSSL require "openssl" unless Object.const_defined? :OpenSSL
if Puma::IS_JRUBY if Puma::IS_JRUBY
@ -217,7 +206,7 @@ class TestPumaServerSSL < Minitest::Test
tcp = Thread.new do tcp = Thread.new do
req_http = Net::HTTP::Get.new "/", {} req_http = Net::HTTP::Get.new "/", {}
# Net::ReadTimeout - TruffleRuby # 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 } http.start.request(req_http) { |rep| body_http = rep.body }
end end
end end