diff options
author | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-12 16:26:05 +0000 |
---|---|---|
committer | akr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2009-09-12 16:26:05 +0000 |
commit | 6f3dbc6f18edafba4d30a239dfb63ab5762adf18 (patch) | |
tree | 1d8762f626ddc9ff7eb841e55074d2db6ff152c0 | |
parent | 2e31a202202f8dc8ac16c717e6e578870ebd7f35 (diff) | |
download | ruby-6f3dbc6f18edafba4d30a239dfb63ab5762adf18.tar.gz ruby-6f3dbc6f18edafba4d30a239dfb63ab5762adf18.tar.xz ruby-6f3dbc6f18edafba4d30a239dfb63ab5762adf18.zip |
test read_timeout.
git-svn-id: http://svn.ruby-lang.org/repos/ruby/trunk@24876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
-rw-r--r-- | test/open-uri/test_open-uri.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/test/open-uri/test_open-uri.rb b/test/open-uri/test_open-uri.rb index 4a4514063..7eb249e91 100644 --- a/test/open-uri/test_open-uri.rb +++ b/test/open-uri/test_open-uri.rb @@ -78,6 +78,31 @@ class TestOpenURI < Test::Unit::TestCase } end + def test_read_timeout + TCPServer.open("127.0.0.1", 0) {|serv| + port = serv.addr[1] + th = Thread.new { + sock = serv.accept + begin + req = sock.gets("\r\n\r\n") + assert_match(%r{\AGET /foo/bar }, req) + sock.print "HTTP/1.0 200 OK\r\n" + sock.print "Content-Length: 4\r\n\r\n" + sleep 1 + sock.print "ab\r\n" + ensure + sock.close + end + } + begin + assert_raise(Timeout::Error) { URI("http://127.0.0.1:#{port}/foo/bar").read(:read_timeout=>0.01) } + ensure + Thread.kill(th) + th.join + end + } + end + def test_invalid_option assert_raise(ArgumentError) { open("http://127.0.0.1/", :invalid_option=>true) {} } end |