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
|
|
|
|
2018-05-09 15:28:12 -03: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 07:24:02 -06:00
|
|
|
begin
|
|
|
|
require 'stopgap_13632'
|
|
|
|
rescue LoadError
|
|
|
|
end
|
2017-08-16 16:07:15 -06:00
|
|
|
end
|
2017-07-19 21:22:36 +03:00
|
|
|
|
2017-02-16 17:54:03 +01:00
|
|
|
begin
|
|
|
|
require "bundler/setup"
|
2018-08-21 20:08:06 -05:00
|
|
|
# bundler/setup may not load bundler
|
|
|
|
require "bundler" unless Bundler.const_defined?(:ORIGINAL_ENV)
|
2017-02-16 17:54:03 +01:00
|
|
|
rescue LoadError
|
2017-04-11 14:48:11 -07:00
|
|
|
warn "Failed to load bundler ... this should only happen during package building"
|
2017-02-16 17:54:03 +01:00
|
|
|
end
|
2017-03-09 00:35:18 +09:00
|
|
|
|
|
|
|
require "net/http"
|
|
|
|
require "timeout"
|
2016-11-22 16:05:49 +01:00
|
|
|
require "minitest/autorun"
|
|
|
|
require "minitest/pride"
|
2007-10-21 02:55:59 +00:00
|
|
|
|
2017-03-03 14:04:56 -08:00
|
|
|
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
|
2017-06-04 05:48:04 -07:00
|
|
|
Thread.abort_on_exception = true
|
2017-03-03 14:04:56 -08:00
|
|
|
|
2017-04-11 14:48:11 -07:00
|
|
|
require "puma"
|
2017-09-22 16:44:21 -04:00
|
|
|
require "puma/events"
|
2017-04-11 14:48:11 -07:00
|
|
|
require "puma/detect"
|
|
|
|
|
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
|
|
|
|
@port = 3211
|
|
|
|
|
|
|
|
def self.call
|
|
|
|
@port += 1
|
|
|
|
@port
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
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
|
|
|
|
|
2016-11-22 16:05:49 +01:00
|
|
|
def run(*)
|
2017-08-16 16:07:15 -06:00
|
|
|
::Timeout.timeout(Puma.jruby? ? 120 : 60, TestTookTooLong) { super }
|
2016-11-20 10:20:58 -07:00
|
|
|
end
|
|
|
|
end
|
2016-11-21 20:10:56 +05:30
|
|
|
|
2017-08-16 16:07:15 -06:00
|
|
|
if ENV['CI']
|
|
|
|
Minitest::Test.prepend TimeoutEveryTestCase
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
@@next_port = 9000
|
|
|
|
|
|
|
|
# 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
|
|
|
|
NO_FORK_MSG = "Kernel.fork isn't available on the #{RUBY_PLATFORM} platform"
|
|
|
|
|
|
|
|
# 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"
|
|
|
|
|
|
|
|
# usage: skip_unless_signal_exist? :USR2
|
|
|
|
def skip_unless_signal_exist?(sig, bt: caller)
|
|
|
|
signal = sig.to_s
|
|
|
|
unless Signal.list.key? signal
|
|
|
|
skip "Signal #{signal} isn't available on the #{RUBY_PLATFORM} platform", bt
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2018-08-21 20:08:06 -05: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)
|
|
|
|
skip_msg = false
|
|
|
|
engs.each do |eng|
|
|
|
|
skip_msg = case eng
|
|
|
|
when :jruby then "Skipped on JRuby#{suffix}" if Puma.jruby?
|
|
|
|
when :windows then "Skipped on Windows#{suffix}" if Puma.windows?
|
|
|
|
when :appveyor then "Skipped on Appveyor#{suffix}" if ENV["APPVEYOR"]
|
|
|
|
when :ci then "Skipped on ENV['CI']#{suffix}" if ENV["CI"]
|
|
|
|
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
|
|
|
|
when :jruby then "Skip unless JRuby" unless Puma.jruby?
|
|
|
|
when :windows then "Skip unless Windows" unless Puma.windows?
|
|
|
|
else false
|
|
|
|
end
|
|
|
|
skip skip_msg, bt if skip_msg
|
2017-07-27 21:18:58 +03:00
|
|
|
end
|
2019-02-20 13:50:35 -06:00
|
|
|
|
|
|
|
def next_port(incr = 1)
|
|
|
|
@@next_port += incr
|
|
|
|
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
|