Skip to content

Commit cd54d0f

Browse files
ko1claude
andcommitted
Fix flaky TestGc#test_stat_single by disabling GC
test_stat_single fails intermittently: 1) Failure: TestGc#test_stat_single [test/ruby/test_gc.rb:198]: <12> expected but was <13>. The test reads the full GC.stat hash and then GC.stat(:count) separately and asserts they are equal: stat = GC.stat assert_equal stat[:count], GC.stat(:count) These are two separate reads of :count. If a GC runs between them, :count increases and the reads disagree (stat[:count] < GC.stat(:count)). A GC in that window can be triggered by an allocation on another thread; running the two reads in a loop with a background allocating thread reproduces it deterministically (54/2,000,000 mismatches; 0 after the fix). The exact source of the GC in the failing CI run is unclear (test-all runs each test process independently), so rather than chase the trigger, disable GC around the two reads (matching test_stat_heap etc.) so :count cannot change between them. CI: https://ci.rvm.jp/results/trunk@ruby-sp3/6395611 log: https://ci.rvm.jp/logfiles/brlog.trunk.20260629-050802 Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
1 parent 8e6fd8f commit cd54d0f

1 file changed

Lines changed: 8 additions & 2 deletions

File tree

test/ruby/test_gc.rb

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -194,8 +194,14 @@ def test_stat_argument
194194
def test_stat_single
195195
omit 'stress' if GC.stress
196196

197-
stat = GC.stat
198-
assert_equal stat[:count], GC.stat(:count)
197+
# GC.stat and GC.stat(:count) are two separate reads of :count. If a GC
198+
# runs between them (e.g. triggered by an allocation on another thread),
199+
# :count changes and the two reads disagree. Disable GC so both reads
200+
# observe the same :count.
201+
EnvUtil.without_gc do
202+
stat = GC.stat
203+
assert_equal stat[:count], GC.stat(:count)
204+
end
199205
assert_raise(ArgumentError){ GC.stat(:invalid) }
200206
end
201207

0 commit comments

Comments
 (0)