From 26508bbc46bcda703c8d76a3b287f71e3967bdbd Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Thu, 26 Jun 2025 11:34:31 -0400 Subject: Fix flaky TestGc#test_heaps_grow_independently The test sometimes fails with "Expected 2062788 to be < 2000000" because heap 0 has not been cleared yet by GC. This commit fixes it to run GC before the assertion to ensure that it does not flake. --- test/ruby/test_gc.rb | 5 +++++ 1 file changed, 5 insertions(+) (limited to 'test/ruby') diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 3516cefedf..85022cbc4d 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -701,6 +701,11 @@ class TestGc < Test::Unit::TestCase allocate_large_object end + # Running GC here is required to prevent this test from being flaky because + # the heap for the small transient objects may not have been cleared by the + # GC causing heap_available_slots to be slightly over 2 * COUNT. + GC.start + heap_available_slots = GC.stat(:heap_available_slots) assert_operator(heap_available_slots, :<, COUNT * 2, "GC.stat: #{GC.stat}\nGC.stat_heap: #{GC.stat_heap}") -- cgit v1.2.3