Skip to content

Commit a8d63ec

Browse files
committed
Fix flaky test_AREF_fstring_key
The code between the two ObjectSpace.count_objects could trigger a GC, which could free string objects causing this test to fail. We can see this failure on CI http://ci.rvm.jp/results/trunk-random2@ruby-sp2-noble-docker/5651016 TestHashOnly#test_AREF_fstring_key [test/ruby/test_hash.rb:1991]: <197483> expected but was <129689>.
1 parent 9ec8dc9 commit a8d63ec

File tree

1 file changed

+6
-3
lines changed

1 file changed

+6
-3
lines changed

test/ruby/test_hash.rb

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1986,9 +1986,12 @@ def test_AREF_fstring_key
19861986
ObjectSpace.count_objects
19871987

19881988
h = {"abc" => 1}
1989-
before = ObjectSpace.count_objects[:T_STRING]
1990-
5.times{ h["abc"] }
1991-
assert_equal before, ObjectSpace.count_objects[:T_STRING]
1989+
1990+
EnvUtil.without_gc do
1991+
before = ObjectSpace.count_objects[:T_STRING]
1992+
5.times{ h["abc"] }
1993+
assert_equal before, ObjectSpace.count_objects[:T_STRING]
1994+
end
19921995
end
19931996

19941997
def test_AREF_fstring_key_default_proc

0 commit comments

Comments
 (0)