diff options
author | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-10 09:42:31 +0000 |
---|---|---|
committer | nobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e> | 2014-01-10 09:42:31 +0000 |
commit | b89a88f043b46a98821b6ccfbb94f469bf403e58 (patch) | |
tree | 163667f852ff85f9ae297b92d7c848289b603e34 /test/test_weakref.rb | |
parent | e85e95c409dbda989c8a815dcf7adcac1306b3f5 (diff) |
test_weakref.rb: find collected weakref
* test/test_weakref.rb (test_recycled): retry and find a WeakRef
whose the target is collected, to fix circumstance dependent.
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@44555 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'test/test_weakref.rb')
-rw-r--r-- | test/test_weakref.rb | 11 |
1 files changed, 8 insertions, 3 deletions
diff --git a/test/test_weakref.rb b/test/test_weakref.rb index 85820b17b8..f12e943423 100644 --- a/test/test_weakref.rb +++ b/test/test_weakref.rb @@ -19,9 +19,14 @@ class TestWeakRef < Test::Unit::TestCase end def test_recycled - weak = make_weakref - ObjectSpace.garbage_collect - ObjectSpace.garbage_collect + weaks = [] + weak = nil + 100.times do + weaks << make_weakref + ObjectSpace.garbage_collect + ObjectSpace.garbage_collect + break if weak = weaks.find {|w| !w.weakref_alive?} + end assert_raise(WeakRef::RefError) {weak.to_s} assert_not_predicate(weak, :weakref_alive?) end |