summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorPeter Zhu <peter@peterzhu.ca>2024-08-30 15:17:06 -0400
committerPeter Zhu <peter@peterzhu.ca>2024-09-02 18:14:48 -0400
commit1b82d6346227dd451003802a09f4abed5eb732bd (patch)
treef8ea626709b892958dcac49c4a6bcfb61fbcf3f1 /test/ruby
parentc1fecc5eabba5bb22a3ebd5616fa50ad612ef4d9 (diff)
Fix flaky test_latest_gc_info_need_major_by
It's possible for a GC to run between the calls of GC.latest_gc_info, which would cause the test to fail. We can disable GC so that GC only triggers manually.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_gc.rb20
1 files changed, 11 insertions, 9 deletions
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 9029f2bda8..43444fe8e7 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -374,15 +374,17 @@ class TestGc < Test::Unit::TestCase
objects.append(100.times.map { '*' })
end
- # We need to ensure that no GC gets ran before the call to GC.start since
- # it would trigger a major GC. Assertions could allocate objects and
- # trigger a GC so we don't run assertions until we perform the major GC.
- need_major_by = GC.latest_gc_info(:need_major_by)
- GC.start(full_mark: false) # should be upgraded to major
- major_by = GC.latest_gc_info(:major_by)
-
- assert_not_nil(need_major_by)
- assert_not_nil(major_by)
+ EnvUtil.without_gc do
+ # We need to ensure that no GC gets ran before the call to GC.start since
+ # it would trigger a major GC. Assertions could allocate objects and
+ # trigger a GC so we don't run assertions until we perform the major GC.
+ need_major_by = GC.latest_gc_info(:need_major_by)
+ GC.start(full_mark: false) # should be upgraded to major
+ major_by = GC.latest_gc_info(:major_by)
+
+ assert_not_nil(need_major_by)
+ assert_not_nil(major_by)
+ end
end
def test_latest_gc_info_weak_references_count