1
0
Fork 0
mirror of https://github.com/ruby/ruby.git synced 2022-11-09 12:17:21 -05:00
ruby--ruby/test/drb/ut_timerholder.rb
seki 021e8ead5c use finalizer trick instead of thread.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@55118 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
2016-05-22 11:03:43 +00:00

74 lines
1.5 KiB
Ruby

# frozen_string_literal: false
require 'test/unit'
require 'drb/timeridconv'
module DRbTests
class TimerIdConvTest < Test::Unit::TestCase
def test_usecase_01
keeping = 0.1
idconv = DRb::TimerIdConv.new(keeping)
key = idconv.to_id(self)
assert_equal(key, self.__id__)
sleep(keeping)
assert_equal(idconv.to_id(false), false.__id__)
assert_equal(idconv.to_obj(key), self)
sleep(keeping)
assert_equal(idconv.to_obj(key), self)
sleep(keeping)
assert_equal(idconv.to_id(true), true.__id__)
sleep(keeping)
assert_raise do
assert_equal(idconv.to_obj(key), self)
end
assert_raise do
assert_equal(idconv.to_obj(false.__id__), false)
end
key = idconv.to_id(self)
assert_equal(key, self.__id__)
assert_equal(idconv.to_id(true), true.__id__)
sleep(keeping)
GC.start
sleep(keeping)
GC.start
assert_raise do
assert_equal(idconv.to_obj(key), self)
end
end
def test_usecase_02
keeping = 0.1
idconv = DRb::TimerIdConv.new(keeping)
key = idconv.to_id(self)
assert_equal(key, self.__id__)
sleep(keeping)
GC.start
sleep(keeping)
GC.start
assert_raise do
assert_equal(idconv.to_obj(key), self)
end
GC.start
key = idconv.to_id(self)
assert_equal(key, self.__id__)
sleep(keeping)
GC.start
sleep(keeping)
GC.start
assert_raise do
assert_equal(idconv.to_obj(key), self)
end
end
end
end