2003-10-20 11:24:00 -04:00
|
|
|
require 'runit/testcase'
|
|
|
|
require 'runit/cui/testrunner'
|
|
|
|
require 'timerholder'
|
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
module DRbTests
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
class TimerHolderTest < RUNIT::TestCase
|
|
|
|
def do_test(timeout, keeper_sleep = nil)
|
|
|
|
holder = TimerHolder.new(timeout)
|
|
|
|
holder.keeper_sleep = keeper_sleep if keeper_sleep
|
|
|
|
key = holder.add(self)
|
|
|
|
sleep(timeout * 0.5)
|
|
|
|
assert_equal(holder.peek(key), self)
|
|
|
|
holder.delete(key)
|
|
|
|
assert(!holder.include?(key))
|
|
|
|
key = holder.add(self)
|
|
|
|
sleep(timeout+0.5)
|
|
|
|
assert_equal(holder.fetch(key), nil)
|
|
|
|
key = holder.add(self)
|
|
|
|
assert_equal(holder.fetch(key), self)
|
|
|
|
holder.store(key, true)
|
|
|
|
assert_equal(holder.fetch(key), true)
|
|
|
|
assert_equal(holder.include?(key), true)
|
|
|
|
sleep(timeout+0.5)
|
|
|
|
assert_exception(TimerHolder::InvalidIndexError) do
|
|
|
|
holder.store(key, 1)
|
|
|
|
end
|
|
|
|
assert_equal(holder.include?(key), false)
|
|
|
|
key = holder.add(self)
|
|
|
|
sleep(timeout * 0.5)
|
|
|
|
assert(holder.include?(key))
|
|
|
|
holder.extend(key, timeout)
|
|
|
|
sleep(timeout * 0.5)
|
|
|
|
assert(holder.include?(key))
|
|
|
|
sleep(timeout * 0.6)
|
|
|
|
assert(!holder.include?(key))
|
|
|
|
holder.delete(key)
|
|
|
|
end
|
2009-03-05 22:56:38 -05:00
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
def test_00
|
|
|
|
do_test(0.5)
|
|
|
|
end
|
|
|
|
|
|
|
|
def test_01
|
|
|
|
do_test(1, 0.5)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-05-31 23:07:58 -04:00
|
|
|
end
|
|
|
|
|
2003-10-20 11:24:00 -04:00
|
|
|
if __FILE__ == $0
|
2014-05-31 23:07:58 -04:00
|
|
|
RUNIT::CUI::TestRunner.run(DRbTests::TimerHolderTest.suite)
|
2003-10-20 11:24:00 -04:00
|
|
|
end
|