From bf2c18731d50075bb64e2639c097396276196cd9 Mon Sep 17 00:00:00 2001 From: Peter Zhu Date: Thu, 29 Jun 2023 11:52:48 -0400 Subject: [PATCH] Add memory leak test for allocating ST hashes Test for commit f0d08d11dcd404f3146c0d71d6ff743bbc6e7193. --- test/ruby/test_hash.rb | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/test/ruby/test_hash.rb b/test/ruby/test_hash.rb index d9d1ca7dde..e66beef29f 100644 --- a/test/ruby/test_hash.rb +++ b/test/ruby/test_hash.rb @@ -219,6 +219,15 @@ class TestHash < Test::Unit::TestCase assert_equal('default', h['spurious']) end + def test_st_literal_memory_leak + assert_no_memory_leak([], "", "#{<<~'end;'}", rss: true) + 1_000_000.times do + # >8 element hashes are ST allocated rather than AR allocated + {a: 1, b: 2, c: 3, d: 4, e: 5, f: 6, g: 7, h: 8, i: 9} + end + end; + end + def test_try_convert assert_equal({1=>2}, Hash.try_convert({1=>2})) assert_equal(nil, Hash.try_convert("1=>2"))