summaryrefslogtreecommitdiff
path: root/test/ruby
diff options
context:
space:
mode:
authorPeter Zhu <[email protected]>2024-06-21 11:41:32 -0400
committerPeter Zhu <[email protected]>2024-07-05 09:15:32 -0400
commit1afcaa3e4b4338191cdc337ed43bc92637be26b5 (patch)
tree4e799c6277b500119ba60f9807f2a0e89b076453 /test/ruby
parent685a4e5be77ec376f29a180c7ed9fbee23e05bac (diff)
Fix flaky test_stat_heap_all
We only collect GC.stat_heap(nil, stat_heap_all) once, outside of the loop, but assert_equal could allocate objects which can cause a GC to run and cause stat_heap_all to be out-of-sync.
Diffstat (limited to 'test/ruby')
-rw-r--r--test/ruby/test_gc.rb9
1 files changed, 4 insertions, 5 deletions
diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb
index 0793fe2b49..25625c41cb 100644
--- a/test/ruby/test_gc.rb
+++ b/test/ruby/test_gc.rb
@@ -186,13 +186,12 @@ class TestGc < Test::Unit::TestCase
omit "flaky with RJIT, which allocates objects itself" if defined?(RubyVM::RJIT) && RubyVM::RJIT.enabled?
stat_heap_all = {}
stat_heap = {}
-
- 2.times do
- GC.stat_heap(0, stat_heap)
- GC.stat_heap(nil, stat_heap_all)
- end
+ # Initialize to prevent GC in future calls
+ GC.stat_heap(0, stat_heap)
+ GC.stat_heap(nil, stat_heap_all)
GC::INTERNAL_CONSTANTS[:SIZE_POOL_COUNT].times do |i|
+ GC.stat_heap(nil, stat_heap_all)
GC.stat_heap(i, stat_heap)
# Remove keys that can vary between invocations