Skip to content

Commit

Permalink
Test Fixes (#2693)
Browse files Browse the repository at this point in the history
1. Move SSLEventsHelper to test/helper.rb, fixes `warning: method redefined`
2. Collapse 'Debugging Info' in Actions log
3. Fix 'shadowed cariable' warning
  • Loading branch information
MSP-Greg committed Sep 7, 2021
1 parent 12acfb3 commit a0cab5d
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 28 deletions.
31 changes: 26 additions & 5 deletions test/helper.rb
Expand Up @@ -27,6 +27,21 @@
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 "<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
# HTTP is some kind of Net::HTTP request object (POST, HEAD, etc.)
def hit(uris)
Expand Down Expand Up @@ -171,8 +186,14 @@ def full_name
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
Expand All @@ -198,9 +219,9 @@ def aggregated_results(io)
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]}")
}
Expand Down
11 changes: 0 additions & 11 deletions test/test_puma_localhost_authority.rb
Expand Up @@ -7,19 +7,8 @@

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 "<unknown>"
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
Expand Down
13 changes: 1 addition & 12 deletions test/test_puma_server_ssl.rb
Expand Up @@ -6,19 +6,8 @@

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 "<unknown>"
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
Expand Down Expand Up @@ -217,7 +206,7 @@ def test_http_rejection
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
Expand Down

0 comments on commit a0cab5d

Please sign in to comment.