/
helper.rb
62 lines (50 loc) · 1.44 KB
/
helper.rb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
# Copyright (c) 2011 Evan Phoenix
# Copyright (c) 2005 Zed A. Shaw
require 'stopgap_13632' if %w(2.2.7 2.3.4 2.4.1).include? RUBY_VERSION
begin
require "bundler/setup"
rescue LoadError
warn "Failed to load bundler ... this should only happen during package building"
end
require "net/http"
require "timeout"
require "minitest/autorun"
require "minitest/pride"
$LOAD_PATH << File.expand_path("../../lib", __FILE__)
Thread.abort_on_exception = true
require "puma"
require "puma/detect"
# 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)
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
end
end
module TimeoutEveryTestCase
# our own subclass so we never confused different timeouts
class TestTookTooLong < Timeout::Error
end
def run(*)
if ENV['CI']
::Timeout.timeout(Puma.jruby? ? 120 : 30, TestTookTooLong) { super }
else
super # we want to be able to use debugger
end
end
end
Minitest::Test.prepend TimeoutEveryTestCase
module SkipTestsBasedOnRubyEngine
def skip_on_jruby
skip "Skipped on JRuby" if Puma.jruby?
end
end
Minitest::Test.include SkipTestsBasedOnRubyEngine