2019-07-27 09:47:19 -07:00
|
|
|
# frozen_string_literal: true
|
2011-09-23 20:46:33 -07:00
|
|
|
# Copyright (c) 2011 Evan Phoenix
|
2016-11-20 10:20:58 -07:00
|
|
|
# Copyright (c) 2005 Zed A. Shaw
|
2006-06-30 20:42:12 +00:00
|
|
|
|
2022-09-10 20:44:41 +09:00
|
|
|
if RUBY_VERSION == '2.4.1'
|
2017-11-20 07:24:02 -06:00
|
|
|
begin
|
|
|
|
require 'stopgap_13632'
|
|
|
|
rescue LoadError
|
2019-07-16 18:53:28 -04:00
|
|
|
puts "For test stability, you must install the stopgap_13632 gem."
|
|
|
|
exit(1)
|
2017-11-20 07:24:02 -06:00
|
|
|
end
|
2017-08-16 16:07:15 -06:00
|
|
|
end
|
2017-07-19 21:22:36 +03:00
|
|
|
|
2020-04-19 17:45:43 -07:00
|
|
|
require_relative "minitest/verbose"
|
2016-11-22 16:05:49 +01:00
|
|
|
require "minitest/autorun"
|
|
|
|
require "minitest/pride"
|
2019-07-27 09:47:19 -07:00
|
|
|
require "minitest/proveit"
|
2020-04-16 18:38:30 -07:00
|
|
|
require "minitest/stub_const"
|
2020-07-22 20:55:47 -05:00
|
|
|
require "net/http"
|
2019-08-12 05:32:46 -05:00
|
|
|
require_relative "helpers/apps"
|
2007-10-21 02:55:59 +00:00
|
|
|
|
2017-06-04 05:48:04 -07:00
|
|
|
Thread.abort_on_exception = true
|
2017-03-03 14:04:56 -08:00
|
|
|
|
2019-09-19 12:37:53 -05:00
|
|
|
$debugging_info = ''.dup
|
2022-09-11 14:33:04 +09:00
|
|
|
$debugging_hold = false # needed for TestCLI#test_control_clustered
|
2021-12-11 22:59:49 +01:00
|
|
|
$test_case_timeout = ENV.fetch("TEST_CASE_TIMEOUT") do
|
|
|
|
RUBY_ENGINE == "ruby" ? 45 : 60
|
|
|
|
end.to_i
|
2019-09-19 12:37:53 -05:00
|
|
|
|
2017-04-11 14:48:11 -07:00
|
|
|
require "puma"
|
|
|
|
require "puma/detect"
|
|
|
|
|
2021-09-07 17:02:00 -05:00
|
|
|
# used in various ssl test files, see test_puma_server_ssl.rb and
|
|
|
|
# test_puma_localhost_authority.rb
|
|
|
|
if Puma::HAS_SSL
|
2022-02-06 02:06:22 +09:00
|
|
|
require 'puma/log_writer'
|
|
|
|
class SSLLogWriterHelper < ::Puma::LogWriter
|
2021-09-07 17:02:00 -05:00
|
|
|
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
|
|
|
|
|
2007-10-21 02:55:59 +00:00
|
|
|
# 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)
|
2017-04-11 14:48:11 -07:00
|
|
|
uris.map do |u|
|
|
|
|
response =
|
|
|
|
if u.kind_of? String
|
|
|
|
Net::HTTP.get(URI.parse(u))
|
|
|
|
else
|
|
|
|
url = URI.parse(u[0])
|
|
|
|
Net::HTTP.new(url.host, url.port).start {|h| h.request(u[1]) }
|
|
|
|
end
|
|
|
|
|
|
|
|
assert response, "Didn't get a response: #{u}"
|
|
|
|
response
|
2007-10-21 02:54:53 +00:00
|
|
|
end
|
2006-05-30 23:36:48 +00:00
|
|
|
end
|
2016-11-20 10:20:58 -07:00
|
|
|
|
2018-03-16 16:26:46 -05:00
|
|
|
module UniquePort
|
|
|
|
def self.call
|
2020-03-24 22:13:31 +01:00
|
|
|
TCPServer.open('127.0.0.1', 0) do |server|
|
|
|
|
server.connect_address.ip_port
|
|
|
|
end
|
2018-03-16 16:26:46 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-07 07:34:35 -06:00
|
|
|
require "timeout"
|
2016-11-20 10:20:58 -07:00
|
|
|
module TimeoutEveryTestCase
|
2017-06-09 05:20:03 -07:00
|
|
|
# our own subclass so we never confused different timeouts
|
|
|
|
class TestTookTooLong < Timeout::Error
|
|
|
|
end
|
|
|
|
|
2020-07-21 22:45:19 -05:00
|
|
|
def run
|
|
|
|
with_info_handler do
|
|
|
|
time_it do
|
|
|
|
capture_exceptions do
|
2021-12-11 22:59:49 +01:00
|
|
|
::Timeout.timeout($test_case_timeout, TestTookTooLong) do
|
2020-10-19 10:22:28 -05:00
|
|
|
before_setup; setup; after_setup
|
2020-07-21 22:45:19 -05:00
|
|
|
self.send self.name
|
2020-10-19 10:22:28 -05:00
|
|
|
end
|
2020-07-21 22:45:19 -05:00
|
|
|
end
|
|
|
|
|
2020-10-19 10:22:28 -05:00
|
|
|
capture_exceptions do
|
2021-12-11 22:59:49 +01:00
|
|
|
::Timeout.timeout($test_case_timeout, TestTookTooLong) do
|
2020-10-19 10:22:28 -05:00
|
|
|
Minitest::Test::TEARDOWN_METHODS.each { |hook| self.send hook }
|
2020-07-21 22:45:19 -05:00
|
|
|
end
|
|
|
|
end
|
2020-09-08 18:27:58 -05:00
|
|
|
if respond_to? :clean_tmp_paths
|
|
|
|
clean_tmp_paths
|
|
|
|
end
|
2020-07-21 22:45:19 -05:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Minitest::Result.from self # per contract
|
2016-11-20 10:20:58 -07:00
|
|
|
end
|
|
|
|
end
|
2016-11-21 20:10:56 +05:30
|
|
|
|
2020-09-08 18:27:58 -05:00
|
|
|
Minitest::Test.prepend TimeoutEveryTestCase
|
2017-08-16 16:07:15 -06:00
|
|
|
if ENV['CI']
|
|
|
|
require 'minitest/retry'
|
|
|
|
Minitest::Retry.use!
|
|
|
|
end
|
2016-11-22 16:05:49 +01:00
|
|
|
|
2019-02-20 13:50:35 -06:00
|
|
|
module TestSkips
|
|
|
|
|
|
|
|
HAS_FORK = ::Process.respond_to? :fork
|
|
|
|
UNIX_SKT_EXIST = Object.const_defined? :UNIXSocket
|
2021-03-15 09:10:43 -05:00
|
|
|
|
|
|
|
MSG_FORK = "Kernel.fork isn't available on #{RUBY_ENGINE} on #{RUBY_PLATFORM}"
|
|
|
|
MSG_UNIX = "UNIXSockets aren't available on the #{RUBY_PLATFORM} platform"
|
|
|
|
MSG_AUNIX = "Abstract UNIXSockets aren't available on the #{RUBY_PLATFORM} platform"
|
2019-02-20 13:50:35 -06:00
|
|
|
|
2019-09-19 12:37:53 -05:00
|
|
|
SIGNAL_LIST = Signal.list.keys.map(&:to_sym) - (Puma.windows? ? [:INT, :TERM] : [])
|
|
|
|
|
2022-05-30 12:26:52 -05:00
|
|
|
JRUBY_HEAD = Puma::IS_JRUBY && RUBY_DESCRIPTION.include?('SNAPSHOT')
|
2020-10-13 17:36:55 -05:00
|
|
|
|
2021-03-15 09:10:43 -05:00
|
|
|
DARWIN = RUBY_PLATFORM.include? 'darwin'
|
|
|
|
|
|
|
|
TRUFFLE = RUBY_ENGINE == 'truffleruby'
|
2022-05-30 12:26:52 -05:00
|
|
|
TRUFFLE_HEAD = TRUFFLE && RUBY_DESCRIPTION.include?('-dev-')
|
2021-03-15 09:10:43 -05:00
|
|
|
|
2019-02-20 13:50:35 -06:00
|
|
|
# usage: skip_unless_signal_exist? :USR2
|
|
|
|
def skip_unless_signal_exist?(sig, bt: caller)
|
2019-09-19 12:37:53 -05:00
|
|
|
signal = sig.to_s.sub(/\ASIG/, '').to_sym
|
|
|
|
unless SIGNAL_LIST.include? signal
|
2019-02-20 13:50:35 -06:00
|
|
|
skip "Signal #{signal} isn't available on the #{RUBY_PLATFORM} platform", bt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2021-03-15 09:10:43 -05:00
|
|
|
# called with one or more params, like skip_if :jruby, :windows
|
2018-08-21 20:08:06 -05:00
|
|
|
# optional suffix kwarg is appended to the skip message
|
|
|
|
# optional suffix bt should generally not used
|
2021-03-15 09:10:43 -05:00
|
|
|
def skip_if(*engs, suffix: '', bt: caller)
|
2018-08-21 20:08:06 -05:00
|
|
|
engs.each do |eng|
|
|
|
|
skip_msg = case eng
|
2021-03-15 09:10:43 -05:00
|
|
|
when :darwin then "Skipped if darwin#{suffix}" if Puma::IS_OSX
|
|
|
|
when :jruby then "Skipped if JRuby#{suffix}" if Puma::IS_JRUBY
|
|
|
|
when :truffleruby then "Skipped if TruffleRuby#{suffix}" if TRUFFLE
|
|
|
|
when :windows then "Skipped if Windows#{suffix}" if Puma::IS_WINDOWS
|
|
|
|
when :ci then "Skipped if ENV['CI']#{suffix}" if ENV['CI']
|
|
|
|
when :no_bundler then "Skipped w/o Bundler#{suffix}" if !defined?(Bundler)
|
|
|
|
when :ssl then "Skipped if SSL is supported" if Puma::HAS_SSL
|
|
|
|
when :fork then "Skipped if Kernel.fork exists" if HAS_FORK
|
|
|
|
when :unix then "Skipped if UNIXSocket exists" if Puma::HAS_UNIX_SOCKET
|
|
|
|
when :aunix then "Skipped if abstract UNIXSocket" if Puma.abstract_unix_socket?
|
2022-09-07 18:27:50 -05:00
|
|
|
when :rack3 then "Skipped if Rack 3.x" if Rack::RELEASE >= '3'
|
2018-08-21 20:08:06 -05:00
|
|
|
else false
|
|
|
|
end
|
|
|
|
skip skip_msg, bt if skip_msg
|
|
|
|
end
|
2016-11-21 20:10:56 +05:30
|
|
|
end
|
2017-07-27 21:18:58 +03:00
|
|
|
|
2018-08-21 20:08:06 -05:00
|
|
|
# called with only one param
|
|
|
|
def skip_unless(eng, bt: caller)
|
|
|
|
skip_msg = case eng
|
2021-03-15 09:10:43 -05:00
|
|
|
when :darwin then "Skip unless darwin" unless Puma::IS_OSX
|
|
|
|
when :jruby then "Skip unless JRuby" unless Puma::IS_JRUBY
|
|
|
|
when :windows then "Skip unless Windows" unless Puma::IS_WINDOWS
|
|
|
|
when :mri then "Skip unless MRI" unless Puma::IS_MRI
|
|
|
|
when :ssl then "Skip unless SSL is supported" unless Puma::HAS_SSL
|
|
|
|
when :fork then MSG_FORK unless HAS_FORK
|
|
|
|
when :unix then MSG_UNIX unless Puma::HAS_UNIX_SOCKET
|
|
|
|
when :aunix then MSG_AUNIX unless Puma.abstract_unix_socket?
|
2022-09-09 00:05:47 -05:00
|
|
|
when :rack3 then "Skipped unless Rack >= 3.x" unless ::Rack::RELEASE >= '3'
|
2018-08-21 20:08:06 -05:00
|
|
|
else false
|
|
|
|
end
|
|
|
|
skip skip_msg, bt if skip_msg
|
2017-07-27 21:18:58 +03:00
|
|
|
end
|
2016-11-21 20:10:56 +05:30
|
|
|
end
|
2016-11-22 16:05:49 +01:00
|
|
|
|
2019-02-20 13:50:35 -06:00
|
|
|
Minitest::Test.include TestSkips
|
2019-07-27 09:47:19 -07:00
|
|
|
|
|
|
|
class Minitest::Test
|
2022-03-30 08:06:46 -06:00
|
|
|
|
|
|
|
REPO_NAME = ENV['GITHUB_REPOSITORY'] ? ENV['GITHUB_REPOSITORY'][/[^\/]+\z/] : 'puma'
|
|
|
|
|
2019-07-27 09:47:19 -07:00
|
|
|
def self.run(reporter, options = {}) # :nodoc:
|
|
|
|
prove_it!
|
|
|
|
super
|
|
|
|
end
|
2019-09-19 12:37:53 -05:00
|
|
|
|
|
|
|
def full_name
|
|
|
|
"#{self.class.name}##{name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Minitest.after_run do
|
|
|
|
# needed for TestCLI#test_control_clustered
|
2022-09-11 14:33:04 +09:00
|
|
|
if !$debugging_hold && ENV['PUMA_TEST_DEBUG']
|
2019-09-19 12:37:53 -05:00
|
|
|
out = $debugging_info.strip
|
|
|
|
unless out.empty?
|
2021-09-07 17:02:00 -05:00
|
|
|
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
|
2019-09-19 12:37:53 -05:00
|
|
|
end
|
|
|
|
end
|
2019-07-27 09:47:19 -07:00
|
|
|
end
|
2021-03-15 09:12:04 -05:00
|
|
|
|
|
|
|
module AggregatedResults
|
|
|
|
def aggregated_results(io)
|
|
|
|
filtered_results = results.dup
|
|
|
|
|
|
|
|
if options[:verbose]
|
|
|
|
skips = filtered_results.select(&:skipped?)
|
|
|
|
unless skips.empty?
|
|
|
|
dash = "\u2500"
|
|
|
|
io.puts '', "Skips:"
|
|
|
|
hsh = skips.group_by { |f| f.failures.first.error.message }
|
|
|
|
hsh_s = {}
|
|
|
|
hsh.each { |k, ary|
|
|
|
|
hsh_s[k] = ary.map { |s|
|
|
|
|
[s.source_location, s.klass, s.name]
|
|
|
|
}.sort_by(&:first)
|
|
|
|
}
|
|
|
|
num = 0
|
|
|
|
hsh_s = hsh_s.sort.to_h
|
|
|
|
hsh_s.each { |k,v|
|
|
|
|
io.puts " #{k} #{dash * 2}".rjust 90, dash
|
|
|
|
hsh_1 = v.group_by { |i| i.first.first }
|
2021-09-07 17:02:00 -05:00
|
|
|
hsh_1.each { |k1,v1|
|
|
|
|
io.puts " #{k1[/\/test\/(.*)/,1]}"
|
|
|
|
v1.each { |item|
|
2021-03-15 09:12:04 -05:00
|
|
|
num += 1
|
|
|
|
io.puts format(" %3s %-5s #{item[1]} #{item[2]}", "#{num})", ":#{item[0][1]}")
|
|
|
|
}
|
|
|
|
puts ''
|
|
|
|
}
|
|
|
|
}
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
filtered_results.reject!(&:skipped?)
|
|
|
|
|
|
|
|
io.puts "Errors & Failures:" unless filtered_results.empty?
|
|
|
|
|
|
|
|
filtered_results.each_with_index { |result, i|
|
|
|
|
io.puts "\n%3d) %s" % [i+1, result]
|
|
|
|
}
|
|
|
|
io.puts
|
|
|
|
io
|
|
|
|
end
|
|
|
|
end
|
|
|
|
Minitest::SummaryReporter.prepend AggregatedResults
|