2019-07-27 12:47:19 -04:00
|
|
|
# frozen_string_literal: true
|
2011-09-23 23:46:33 -04:00
|
|
|
# Copyright (c) 2011 Evan Phoenix
|
2016-11-20 12:20:58 -05:00
|
|
|
# Copyright (c) 2005 Zed A. Shaw
|
2006-06-30 16:42:12 -04:00
|
|
|
|
2018-05-09 14:28:12 -04:00
|
|
|
if %w(2.2.7 2.2.8 2.2.9 2.2.10 2.3.4 2.4.1).include? RUBY_VERSION
|
2017-11-20 08:24:02 -05: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 08:24:02 -05:00
|
|
|
end
|
2017-08-16 18:07:15 -04:00
|
|
|
end
|
2017-07-19 14:22:36 -04:00
|
|
|
|
2020-04-19 20:45:43 -04:00
|
|
|
require_relative "minitest/verbose"
|
2016-11-22 10:05:49 -05:00
|
|
|
require "minitest/autorun"
|
|
|
|
require "minitest/pride"
|
2019-07-27 12:47:19 -04:00
|
|
|
require "minitest/proveit"
|
2020-04-16 21:38:30 -04:00
|
|
|
require "minitest/stub_const"
|
2020-07-22 21:55:47 -04:00
|
|
|
require "net/http"
|
2019-08-12 06:32:46 -04:00
|
|
|
require_relative "helpers/apps"
|
2007-10-20 22:55:59 -04:00
|
|
|
|
2017-06-04 08:48:04 -04:00
|
|
|
Thread.abort_on_exception = true
|
2017-03-03 17:04:56 -05:00
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
$debugging_info = ''.dup
|
|
|
|
$debugging_hold = false # needed for TestCLI#test_control_clustered
|
|
|
|
|
2017-04-11 17:48:11 -04:00
|
|
|
require "puma"
|
|
|
|
require "puma/detect"
|
|
|
|
|
2007-10-20 22:55:59 -04: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 17:48:11 -04: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-20 22:54:53 -04:00
|
|
|
end
|
2006-05-30 19:36:48 -04:00
|
|
|
end
|
2016-11-20 12:20:58 -05:00
|
|
|
|
2018-03-16 17:26:46 -04:00
|
|
|
module UniquePort
|
|
|
|
def self.call
|
2020-03-24 17:13:31 -04:00
|
|
|
TCPServer.open('127.0.0.1', 0) do |server|
|
|
|
|
server.connect_address.ip_port
|
|
|
|
end
|
2018-03-16 17:26:46 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2020-03-07 08:34:35 -05:00
|
|
|
require "timeout"
|
2016-11-20 12:20:58 -05:00
|
|
|
module TimeoutEveryTestCase
|
2017-06-09 08:20:03 -04:00
|
|
|
# our own subclass so we never confused different timeouts
|
|
|
|
class TestTookTooLong < Timeout::Error
|
|
|
|
end
|
|
|
|
|
2020-07-21 23:45:19 -04:00
|
|
|
def run
|
|
|
|
with_info_handler do
|
|
|
|
time_it do
|
|
|
|
capture_exceptions do
|
2020-10-19 11:22:28 -04:00
|
|
|
::Timeout.timeout(RUBY_ENGINE == 'ruby' ? 45 : 60, TestTookTooLong) do
|
|
|
|
before_setup; setup; after_setup
|
2020-07-21 23:45:19 -04:00
|
|
|
self.send self.name
|
2020-10-19 11:22:28 -04:00
|
|
|
end
|
2020-07-21 23:45:19 -04:00
|
|
|
end
|
|
|
|
|
2020-10-19 11:22:28 -04:00
|
|
|
capture_exceptions do
|
|
|
|
::Timeout.timeout(RUBY_ENGINE == 'ruby' ? 45 : 60, TestTookTooLong) do
|
|
|
|
Minitest::Test::TEARDOWN_METHODS.each { |hook| self.send hook }
|
2020-07-21 23:45:19 -04:00
|
|
|
end
|
|
|
|
end
|
2020-09-08 19:27:58 -04:00
|
|
|
if respond_to? :clean_tmp_paths
|
|
|
|
clean_tmp_paths
|
|
|
|
end
|
2020-07-21 23:45:19 -04:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Minitest::Result.from self # per contract
|
2016-11-20 12:20:58 -05:00
|
|
|
end
|
|
|
|
end
|
2016-11-21 09:40:56 -05:00
|
|
|
|
2020-09-08 19:27:58 -04:00
|
|
|
Minitest::Test.prepend TimeoutEveryTestCase
|
2017-08-16 18:07:15 -04:00
|
|
|
if ENV['CI']
|
|
|
|
require 'minitest/retry'
|
|
|
|
Minitest::Retry.use!
|
|
|
|
end
|
2016-11-22 10:05:49 -05:00
|
|
|
|
2019-02-20 14:50:35 -05:00
|
|
|
module TestSkips
|
|
|
|
|
|
|
|
# usage: skip NO_FORK_MSG unless HAS_FORK
|
|
|
|
# windows >= 2.6 fork is not defined, < 2.6 fork raises NotImplementedError
|
|
|
|
HAS_FORK = ::Process.respond_to? :fork
|
2020-03-24 17:13:31 -04:00
|
|
|
NO_FORK_MSG = "Kernel.fork isn't available on #{RUBY_ENGINE} on #{RUBY_PLATFORM}"
|
2019-02-20 14:50:35 -05:00
|
|
|
|
|
|
|
# socket is required by puma
|
|
|
|
# usage: skip UNIX_SKT_MSG unless UNIX_SKT_EXIST
|
|
|
|
UNIX_SKT_EXIST = Object.const_defined? :UNIXSocket
|
|
|
|
UNIX_SKT_MSG = "UnixSockets aren't available on the #{RUBY_PLATFORM} platform"
|
|
|
|
|
2019-09-19 13:37:53 -04:00
|
|
|
SIGNAL_LIST = Signal.list.keys.map(&:to_sym) - (Puma.windows? ? [:INT, :TERM] : [])
|
|
|
|
|
2020-10-13 18:36:55 -04:00
|
|
|
JRUBY_HEAD = Puma::IS_JRUBY && RUBY_DESCRIPTION =~ /SNAPSHOT/
|
|
|
|
|
2019-02-20 14:50:35 -05:00
|
|
|
# usage: skip_unless_signal_exist? :USR2
|
|
|
|
def skip_unless_signal_exist?(sig, bt: caller)
|
2019-09-19 13:37:53 -04:00
|
|
|
signal = sig.to_s.sub(/\ASIG/, '').to_sym
|
|
|
|
unless SIGNAL_LIST.include? signal
|
2019-02-20 14:50:35 -05:00
|
|
|
skip "Signal #{signal} isn't available on the #{RUBY_PLATFORM} platform", bt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
# called with one or more params, like skip_on :jruby, :windows
|
|
|
|
# optional suffix kwarg is appended to the skip message
|
|
|
|
# optional suffix bt should generally not used
|
|
|
|
def skip_on(*engs, suffix: '', bt: caller)
|
|
|
|
engs.each do |eng|
|
|
|
|
skip_msg = case eng
|
2019-09-19 13:50:13 -04:00
|
|
|
when :darwin then "Skipped on darwin#{suffix}" if RUBY_PLATFORM[/darwin/]
|
|
|
|
when :jruby then "Skipped on JRuby#{suffix}" if Puma.jruby?
|
2020-03-24 17:13:31 -04:00
|
|
|
when :truffleruby then "Skipped on TruffleRuby#{suffix}" if RUBY_ENGINE == "truffleruby"
|
2019-09-19 13:50:13 -04:00
|
|
|
when :windows then "Skipped on Windows#{suffix}" if Puma.windows?
|
|
|
|
when :ci then "Skipped on ENV['CI']#{suffix}" if ENV["CI"]
|
2019-09-13 12:44:02 -04:00
|
|
|
when :no_bundler then "Skipped w/o Bundler#{suffix}" if !defined?(Bundler)
|
2018-08-21 21:08:06 -04:00
|
|
|
else false
|
|
|
|
end
|
|
|
|
skip skip_msg, bt if skip_msg
|
|
|
|
end
|
2016-11-21 09:40:56 -05:00
|
|
|
end
|
2017-07-27 14:18:58 -04:00
|
|
|
|
2018-08-21 21:08:06 -04:00
|
|
|
# called with only one param
|
|
|
|
def skip_unless(eng, bt: caller)
|
|
|
|
skip_msg = case eng
|
2019-08-26 13:21:00 -04:00
|
|
|
when :darwin then "Skip unless darwin" unless RUBY_PLATFORM[/darwin/]
|
2018-08-21 21:08:06 -04:00
|
|
|
when :jruby then "Skip unless JRuby" unless Puma.jruby?
|
|
|
|
when :windows then "Skip unless Windows" unless Puma.windows?
|
2019-11-20 09:39:37 -05:00
|
|
|
when :mri then "Skip unless MRI" unless Puma.mri?
|
2018-08-21 21:08:06 -04:00
|
|
|
else false
|
|
|
|
end
|
|
|
|
skip skip_msg, bt if skip_msg
|
2017-07-27 14:18:58 -04:00
|
|
|
end
|
2016-11-21 09:40:56 -05:00
|
|
|
end
|
2016-11-22 10:05:49 -05:00
|
|
|
|
2019-02-20 14:50:35 -05:00
|
|
|
Minitest::Test.include TestSkips
|
2019-07-27 12:47:19 -04:00
|
|
|
|
|
|
|
class Minitest::Test
|
|
|
|
def self.run(reporter, options = {}) # :nodoc:
|
|
|
|
prove_it!
|
|
|
|
super
|
|
|
|
end
|
2019-09-19 13:37:53 -04:00
|
|
|
|
|
|
|
def full_name
|
|
|
|
"#{self.class.name}##{name}"
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
Minitest.after_run do
|
|
|
|
# needed for TestCLI#test_control_clustered
|
|
|
|
unless $debugging_hold
|
|
|
|
out = $debugging_info.strip
|
|
|
|
unless out.empty?
|
|
|
|
puts "", " Debugging Info".rjust(75, '-'),
|
|
|
|
out, '-' * 75, ""
|
|
|
|
end
|
|
|
|
end
|
2019-07-27 12:47:19 -04:00
|
|
|
end
|