mirror of
https://github.com/ruby/ruby.git
synced 2025-08-25 14:05:02 +02:00

started. [ruby-core:28028] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8@26553 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
33 lines
791 B
Ruby
33 lines
791 B
Ruby
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(Errno::ECONNRESET, 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
|