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
|
# File 'lib/tests/http.rb', line 19
def run(runner)
runner.report self, "Testing HTTP server on #{@host} port #{@port}..."
http = Net::HTTP.new(@host, @port)
http.read_timeout = 2
http.open_timeout = 2
@requests.each do |page|
runner.report self, "Trying #{page}..."
request = Net::HTTP::Get.new URI.parse(page).request_uri
begin
response = http.request(request)
rescue Timeout::Error
raise TestFailed, "HTTP connection timed out (Timeout::Error)"
rescue Errno::ETIMEDOUT
raise TestFailed, "HTTP connection timed out (ETIMEDOUT)"
rescue Errno::ECONNREFUSED
raise TestFailed, "HTTP connection refused (ECONNREFUSED)"
rescue SocketError
raise TestFailed, "HTTP connection failed (SocketError)"
end
good_codes = 100...400
code = response.code.to_i
unless good_codes.include? code
raise TestFailed, "Response code #{code} on #{@post}:#{@port} GET #{page}"
end
end
end
|