From ed51e8b8fa9f7e811e69de30f7695dc2242e8e69 Mon Sep 17 00:00:00 2001 From: Nobuyoshi Nakada Date: Tue, 27 Jul 2021 11:47:11 +0900 Subject: [PATCH] Make GCed during suppressing the warning Consume the VM stack more, to make the target object get GCed with more probability during suppressing the warning. --- test/ruby/test_gc.rb | 22 ++++++++++++++-------- 1 file changed, 14 insertions(+), 8 deletions(-) diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 4df9775ecc..02f86a2463 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -451,14 +451,17 @@ class TestGc < Test::Unit::TestCase result << :c2 raise end - tap { - tap { + gen = proc do |depth| + if depth > 0 + gen[depth-1] + else obj = Object.new ObjectSpace.define_finalizer(obj, c1) ObjectSpace.define_finalizer(obj, c2) obj = nil - } - } + end + end + gen[100] EnvUtil.suppress_warning {GC.start} skip "finalizers did not get run" if result.empty? assert_equal([:c1, :c2], result) @@ -474,14 +477,17 @@ class TestGc < Test::Unit::TestCase @result << :c2 raise end - tap { - tap { + gen = proc do |depth| + if depth > 0 + gen[depth-1] + else obj = Object.new ObjectSpace.define_finalizer(obj, method(:c1)) ObjectSpace.define_finalizer(obj, method(:c2)) obj = nil - } - } + end + end + gen[100] EnvUtil.suppress_warning {GC.start} skip "finalizers did not get run" if @result.empty? assert_equal([:c1, :c2], @result)