summaryrefslogtreecommitdiff
path: root/test/open-uri/test_open-uri.rb
diff options
context:
space:
mode:
authorakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-12 16:26:05 +0000
committerakr <akr@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2009-09-12 16:26:05 +0000
commit0466f33486635fe69c9ce1eeb900079bf0a3c0a4 (patch)
tree1d8762f626ddc9ff7eb841e55074d2db6ff152c0 /test/open-uri/test_open-uri.rb
parentdb2be749b470c28f1feee7d33d5774a3ed6cb36b (diff)
test read_timeout.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@24876 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/open-uri/test_open-uri.rb')
-rw-r--r--test/open-uri/test_open-uri.rb25
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 4a45140..7eb249e 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