diff --git a/test/ruby/test_gc.rb b/test/ruby/test_gc.rb index 567e7b5d80458b..b22f5b8a65ed4d 100644 --- a/test/ruby/test_gc.rb +++ b/test/ruby/test_gc.rb @@ -327,7 +327,8 @@ def test_latest_gc_info_weak_references_count # Run full GC again to collect stats about weak references GC.start - assert_equal(0, wmap.size) + # Sometimes the WeakMap has one element, which might be held on by registers. + assert_operator(wmap.size, :<=, 1) assert_operator(GC.latest_gc_info(:weak_references_count), :<=, before_weak_references_count - count + error_tolerance) assert_operator(GC.latest_gc_info(:retained_weak_references_count), :<=, before_retained_weak_references_count - count + error_tolerance)