blob: 4453b83f7a42a97405893831cdfa24e556680dea (
plain)
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
|
require 'net/http'
require 'test/unit'
module TestHTTP
class HTTPConnectionTest < Test::Unit::TestCase
def test_connection_refused_in_request
bug2708 = '[ruby-core:28028]'
port = nil
localhost = "127.0.0.1"
t = Thread.new {
TCPServer.open(localhost, 0) do |serv|
_, port, _, _ = serv.addr
if clt = serv.accept
clt.close
end
end
}
begin
sleep 0.1 until port
assert_raise(EOFError, bug2708) {
n = Net::HTTP.new(localhost, port)
n.request_get('/')
}
ensure
t.join if t
end
assert_raise(Errno::ECONNREFUSED, bug2708) {
n = Net::HTTP.new(localhost, port)
n.request_get('/')
}
end
end
end
|