From 9559b04e3dd6ee3afadb71a35956ccff4d8ef33e Mon Sep 17 00:00:00 2001 From: normal Date: Fri, 10 Oct 2014 19:15:56 +0000 Subject: open-uri: accept :open_timeout option * lib/open-uri.rb (OpenURI::Options): add :open_timeout default * (def OpenURI.open_http): check :open_timeout option * (module OpenURI): rdoc for :open_timeout * test/open-uri/test_open-uri.rb (test_open_timeout): new test [Feature #10361] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@47869 b2dd03c8-39d4-4d8f-98ff-823fe69b080e --- test/open-uri/test_open-uri.rb | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'test/open-uri/test_open-uri.rb') diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index 4073754bd7..51af8842d1 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -122,6 +122,24 @@ class TestOpenURI < Test::Unit::TestCase } end + def test_open_timeout + assert_raises(Net::OpenTimeout) do + URI("http://example.com/").read(open_timeout: 0.000001) + end if false # avoid external resources in tests + + with_http {|srv, dr, url| + url += '/' + srv.mount_proc('/', lambda { |_, res| res.body = 'hi' }) + begin + URI(url).read(open_timeout: 0.000001) + rescue Net::OpenTimeout + # not guaranteed to fire, since the kernel negotiates the + # TCP connection even if the server thread is sleeping + end + assert_equal 'hi', URI(url).read(open_timeout: 60), 'should not timeout' + } + end + def test_invalid_option assert_raise(ArgumentError) { open("http://127.0.0.1/", :invalid_option=>true) {} } end -- cgit v1.2.3