summaryrefslogtreecommitdiff
path: root/test/json/test_json.rb
diff options
context:
space:
mode:
Diffstat (limited to 'test/json/test_json.rb')
-rwxr-xr-xtest/json/test_json.rb13
1 files changed, 13 insertions, 0 deletions
diff --git a/test/json/test_json.rb b/test/json/test_json.rb
index 46f000148f..96ba744478 100755
--- a/test/json/test_json.rb
+++ b/test/json/test_json.rb
@@ -560,4 +560,17 @@ EOT
assert_equal(Encoding::UTF_8, e.message.encoding, bug10705)
assert_include(e.message, json, bug10705)
end if defined?(Encoding::UTF_8)
+
+ if EnvUtil.gc_stress_to_class?
+ def assert_no_memory_leak(code, *rest, **opt)
+ code = "8.times {20_000.times {begin #{code}; rescue NoMemoryError; end}; GC.start}"
+ super(["-rjson/ext/parser"],
+ "GC.add_stress_to_class(JSON::Ext::Parser); "\
+ "#{code}", code, *rest, rss: true, limit: 1.1, **opt)
+ end
+
+ def test_no_memory_leak_allocate
+ assert_no_memory_leak("JSON::Ext::Parser.allocate")
+ end
+ end
end