mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
webrick/test_utils.rb: no timeout during assertion
* test/webrick/test_utils.rb (assert_expired): separate negated assertion and block timeout excecptions. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@51237 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
cb04140542
commit
1c4fe8df9f
1 changed files with 16 additions and 11 deletions
|
@ -2,10 +2,15 @@ require "test/unit"
|
||||||
require "webrick/utils"
|
require "webrick/utils"
|
||||||
|
|
||||||
class TestWEBrickUtils < Test::Unit::TestCase
|
class TestWEBrickUtils < Test::Unit::TestCase
|
||||||
def assert_expired(flag, m)
|
def assert_expired(m)
|
||||||
if m == WEBrick::Utils
|
Thread.handle_interrupt(Timeout::Error => :never, EX => :never) do
|
||||||
handler = WEBrick::Utils::TimeoutHandler.instance
|
assert_empty(m::TimeoutHandler.instance.instance_variable_get(:@timeout_info))
|
||||||
assert_equal(flag, handler.instance_variable_get(:@timeout_info).empty?)
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
def assert_not_expired(m)
|
||||||
|
Thread.handle_interrupt(Timeout::Error => :never, EX => :never) do
|
||||||
|
assert_not_empty(m::TimeoutHandler.instance.instance_variable_get(:@timeout_info))
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -14,7 +19,7 @@ class TestWEBrickUtils < Test::Unit::TestCase
|
||||||
def test_no_timeout
|
def test_no_timeout
|
||||||
m = WEBrick::Utils
|
m = WEBrick::Utils
|
||||||
assert_equal(:foo, m.timeout(10){ :foo })
|
assert_equal(:foo, m.timeout(10){ :foo })
|
||||||
assert_expired(true, m)
|
assert_expired(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_timeout_outer
|
def test_nested_timeout_outer
|
||||||
|
@ -23,26 +28,26 @@ class TestWEBrickUtils < Test::Unit::TestCase
|
||||||
assert_raise(Timeout::Error){
|
assert_raise(Timeout::Error){
|
||||||
m.timeout(0.02){
|
m.timeout(0.02){
|
||||||
assert_raise(Timeout::Error){ m.timeout(0.01){ i += 1; sleep } }
|
assert_raise(Timeout::Error){ m.timeout(0.01){ i += 1; sleep } }
|
||||||
assert_expired(false, m)
|
assert_not_expired(m)
|
||||||
i += 1
|
i += 1
|
||||||
sleep
|
sleep
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
assert_equal(2, i)
|
assert_equal(2, i)
|
||||||
assert_expired(true, m)
|
assert_expired(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_timeout_default_execption
|
def test_timeout_default_execption
|
||||||
m = WEBrick::Utils
|
m = WEBrick::Utils
|
||||||
assert_raise(Timeout::Error){ m.timeout(0.01){ sleep } }
|
assert_raise(Timeout::Error){ m.timeout(0.01){ sleep } }
|
||||||
assert_expired(true, m)
|
assert_expired(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_timeout_custom_exception
|
def test_timeout_custom_exception
|
||||||
m = WEBrick::Utils
|
m = WEBrick::Utils
|
||||||
ex = EX
|
ex = EX
|
||||||
assert_raise(ex){ m.timeout(0.01, ex){ sleep } }
|
assert_raise(ex){ m.timeout(0.01, ex){ sleep } }
|
||||||
assert_expired(true, m)
|
assert_expired(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_timeout_inner_custom_exception
|
def test_nested_timeout_inner_custom_exception
|
||||||
|
@ -56,7 +61,7 @@ class TestWEBrickUtils < Test::Unit::TestCase
|
||||||
sleep
|
sleep
|
||||||
}
|
}
|
||||||
assert_equal(1, i)
|
assert_equal(1, i)
|
||||||
assert_expired(true, m)
|
assert_expired(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_nested_timeout_outer_custom_exception
|
def test_nested_timeout_outer_custom_exception
|
||||||
|
@ -70,7 +75,7 @@ class TestWEBrickUtils < Test::Unit::TestCase
|
||||||
sleep
|
sleep
|
||||||
}
|
}
|
||||||
assert_equal(1, i)
|
assert_equal(1, i)
|
||||||
assert_expired(true, m)
|
assert_expired(m)
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_create_listeners
|
def test_create_listeners
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue