diff options
Diffstat (limited to 'test/net/http')
-rw-r--r-- | test/net/http/test_http.rb | 19 | ||||
-rw-r--r-- | test/net/http/test_https.rb | 22 |
2 files changed, 41 insertions, 0 deletions
diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 036a6a1570..18ca79e721 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -182,6 +182,25 @@ module TestNetHTTP_version_1_1_methods assert_equal data, res.entity end + def test_timeout_during_HTTP_session + bug4246 = "expected the HTTP session to have timed out but have not. c.f. [ruby-core:34203]" + + # listen for connections... but deliberately do not complete SSL handshake + TCPServer.open(0) {|server| + port = server.addr[1] + + conn = Net::HTTP.new('localhost', port) + conn.read_timeout = 1 + conn.open_timeout = 1 + + th = Thread.new do + assert_raise(Timeout::Error) { + conn.get('/') + } + end + assert th.join(10), bug4246 + } + end end diff --git a/test/net/http/test_https.rb b/test/net/http/test_https.rb index 95c63da750..8da7090c68 100644 --- a/test/net/http/test_https.rb +++ b/test/net/http/test_https.rb @@ -2,6 +2,7 @@ require "test/unit" begin require 'net/https' require 'stringio' + require 'timeout' require File.expand_path("../../openssl/utils", File.dirname(__FILE__)) require File.expand_path("utils", File.dirname(__FILE__)) rescue LoadError @@ -104,4 +105,25 @@ class TestNetHTTPS < Test::Unit::TestCase } assert_match(/hostname does not match/, ex.message) end + + def test_timeout_during_SSL_handshake + bug4246 = "expected the SSL connection to have timed out but have not. [ruby-core:34203]" + + # listen for connections... but deliberately do not complete SSL handshake + TCPServer.open(0) {|server| + port = server.addr[1] + + conn = Net::HTTP.new('localhost', port) + conn.use_ssl = true + conn.read_timeout = 1 + conn.open_timeout = 1 + + th = Thread.new do + assert_raise(Timeout::Error) { + conn.get('/') + } + end + assert th.join(10), bug4246 + } + end end if defined?(OpenSSL) |