From bee7ccddd254c7b6e781f5ea9bbf651b50b590ee Mon Sep 17 00:00:00 2001 From: naruse Date: Fri, 20 Jan 2012 05:56:35 +0000 Subject: * lib/net/http.rb (Net::HTTP#transport_request): retry a idempotent request automatically. [ruby-dev:45030] [Bug #5790] [ruby-core:41821] [Bug #5813] * lib/net/http.rb (Net::HTTP#keep_alive_timeout=): added to specify the second to reconnect the TCP connection on Keep-Alive. The default value is 2 second because current servers uses 2 sec. http://ftp-admin.blogspot.com/2009/09/keepalivetimeout2.html * lib/net/http.rb (Net::HTTP#begin_transport): reconnect TCP connection on keep-alive timeout. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@34341 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/net/http/test_http.rb | 44 ++++++++++++++++++++++++++++++++++++++++++++ test/net/http/utils.rb | 1 + 2 files changed, 45 insertions(+) (limited to 'test/net/http') diff --git a/test/net/http/test_http.rb b/test/net/http/test_http.rb index 15158546f1..b27aeb1cdc 100644 --- a/test/net/http/test_http.rb +++ b/test/net/http/test_http.rb @@ -564,3 +564,47 @@ class TestNetHTTPContinue < Test::Unit::TestCase assert_not_match(/HTTP\/1.1 100 continue/, @debug.string) end end + +class TestNetHTTPKeepAlive < Test::Unit::TestCase + CONFIG = { + 'host' => '127.0.0.1', + 'port' => 10081, + 'proxy_host' => nil, + 'proxy_port' => nil, + 'RequestTimeout' => 1, + } + + include TestNetHTTPUtils + + def test_keep_alive_get_auto_reconnect + start {|http| + http.set_debug_output($stderr) + res = http.get('/') + http.keep_alive_timeout = 1 + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + sleep 1.5 + assert_nothing_raised { + res = http.get('/') + } + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + } + end + + def test_keep_alive_get_auto_retry + start {|http| + http.set_debug_output($stderr) + res = http.get('/') + http.keep_alive_timeout = 5 + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + sleep 1.5 + assert_nothing_raised { + res = http.get('/') + } + assert_kind_of Net::HTTPResponse, res + assert_kind_of String, res.body + } + end +end diff --git a/test/net/http/utils.rb b/test/net/http/utils.rb index 50f616f29f..07e0b9fa2d 100644 --- a/test/net/http/utils.rb +++ b/test/net/http/utils.rb @@ -51,6 +51,7 @@ module TestNetHTTPUtils :ServerType => Thread, } server_config[:OutputBufferSize] = 4 if config('chunked') + server_config[:RequestTimeout] = config('RequestTimeout') if config('RequestTimeout') if defined?(OpenSSL) and config('ssl_enable') server_config.update({ :SSLEnable => true, -- cgit v1.2.3