From ce436ff3e3cbd6810d7cf83fedbd2b55995ca0b1 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Mon, 18 Dec 2023 13:30:24 -0500 Subject: [PATCH] Fix flaky test test_stat_heap The test sometimes fails with: 1) Failure: TestGc#test_stat_heap [/tmp/ruby/src/trunk-repeat50/test/ruby/test_gc.rb:169]: Expected 33434403 to be <= 33434354. --- test/ruby/test_gc.rb | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 5111b05001..a577fcb16b 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -151,8 +151,13 @@ class TestGc < Test::Unit::TestCase GC.stat(stat) GC::INTERNAL_CONSTANTS[:SIZE_POOL_COUNT].times do |i| - GC.stat_heap(i, stat_heap) - GC.stat(stat) + begin + reenable_gc = !GC.disable + GC.stat_heap(i, stat_heap) + GC.stat(stat) + ensure + GC.enable if reenable_gc + end assert_equal GC::INTERNAL_CONSTANTS[:RVALUE_SIZE] * (2**i), stat_heap[:slot_size] assert_operator stat_heap[:heap_allocatable_pages], :<=, stat[:heap_allocatable_pages]