diff options
-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 4a4514063f..7eb249e914 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 |