mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
9a012539ba
:InputBufferSize and :OutputBufferSize. * lib/webrick/utils.rb (WEBrick::Utils.timeout): add new timeout method. this implementation is expected to be compatible with timeout.rb and faster than timeout.rb. * lib/webrick/httprequest.rb (WEBrick::HTTPRequest#_read_data): Timeout.timeout is replaced by WEBrick::Utils.timeout. * lib/webrick/httprequest.rb: WEBrick::HTTPRequest::BUFSIZE is replaced by config[:InputBufferSize]. * lib/webrick/httpresposne.rb: WEBrick::HTTPResponse::BUFSIZE is replaced by config[:OutputBufferSize]. * lib/webrick/server.rb: get rid of unnecessary require. * test/webrick/test_utils.rb: test for WEBrick::Utils.timeout. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@10167 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
64 lines
1.3 KiB
Ruby
64 lines
1.3 KiB
Ruby
require "test/unit"
|
|
require "webrick/utils"
|
|
|
|
class TestWEBrickUtils < Test::Unit::TestCase
|
|
def assert_expired(flag, m)
|
|
if m == WEBrick::Utils
|
|
handler = WEBrick::Utils::TimeoutHandler.instance
|
|
assert_equal(flag, handler.instance_eval{ @timeout_info.empty? })
|
|
end
|
|
end
|
|
|
|
def do_test_timeout(m)
|
|
ex = Class.new(StandardError)
|
|
|
|
assert_equal(:foo, m.timeout(10){ :foo })
|
|
assert_expired(true, m)
|
|
|
|
i = 0
|
|
assert_raises(Timeout::Error){
|
|
m.timeout(2){
|
|
assert_raises(Timeout::Error){ m.timeout(1){ i += 1; sleep } }
|
|
assert_expired(false, m)
|
|
i += 1
|
|
sleep
|
|
}
|
|
}
|
|
assert_equal(2, i)
|
|
assert_expired(true, m)
|
|
|
|
assert_raises(Timeout::Error){ m.timeout(0.1){ sleep } }
|
|
assert_expired(true, m)
|
|
|
|
assert_raises(ex){ m.timeout(0.1, ex){ sleep } }
|
|
assert_expired(true, m)
|
|
|
|
i = 0
|
|
assert_raises(ex){
|
|
m.timeout(10){
|
|
m.timeout(1, ex){ i += 1; sleep }
|
|
}
|
|
sleep
|
|
}
|
|
assert_equal(1, i)
|
|
assert_expired(true, m)
|
|
|
|
i = 0
|
|
assert_raises(Timeout::Error){
|
|
m.timeout(1){
|
|
m.timeout(10, ex){ i += 1; sleep }
|
|
}
|
|
sleep
|
|
}
|
|
assert_equal(1, i)
|
|
assert_expired(true, m)
|
|
end
|
|
|
|
def test_webrick_timeout
|
|
do_test_timeout(WEBrick::Utils)
|
|
end
|
|
|
|
#def test_timeout
|
|
# do_test_timeout(Timeout)
|
|
#end
|
|
end
|