summaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorshyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-22 10:50:54 +0000
committershyouhei <shyouhei@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2010-05-22 10:50:54 +0000
commitb6b1a387f1637aae55d9d7636d03db49b46ea75f (patch)
tree818ea9673eca2934917237ec2d5cfc29870be789 /test
parent5fe5a24586ac9a698e0a9c8f0f6d4684e1d2609d (diff)
merge revision(s) 26553:
* lib/net/http.rb (Net::HTTP#request): close @socket only after started. [ruby-core:28028] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/branches/ruby_1_8_7@27955 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test')
-rw-r--r--test/net/http/test_connection.rb33
1 files changed, 33 insertions, 0 deletions
diff --git a/test/net/http/test_connection.rb b/test/net/http/test_connection.rb
new file mode 100644
index 0000000000..d5610ce1d8
--- /dev/null
+++ b/test/net/http/test_connection.rb
@@ -0,0 +1,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(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