Skip to content

Commit 0ccaa5f

Browse files
committed
test: add a test for the eval-leak fix
1 parent e2f0b64 commit 0ccaa5f

File tree

1 file changed

+14
-0
lines changed

1 file changed

+14
-0
lines changed

tests/test_oddball.py

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,20 @@ def once(x): # line 301
206206
if fails > 8:
207207
pytest.fail("RAM grew by %d" % (ram_growth)) # pragma: only failure
208208

209+
@pytest.mark.skipif(not testenv.C_TRACER, reason="Only the C tracer has refcounting issues")
210+
# In fact, sysmon explicitly holds onto all code objects,
211+
# so this will definitely fail with sysmon.
212+
def test_eval_codeobject_leak(self) -> None:
213+
code = """\
214+
for i in range(100_000):
215+
r = eval("'a' + '1'")
216+
assert r == 'a1'
217+
"""
218+
ram_0 = osinfo.process_ram()
219+
self.check_coverage(code, [1, 2, 3], "")
220+
ram_growth = osinfo.process_ram() - ram_0
221+
assert ram_growth < 2_000 * 1024
222+
209223

210224
class MemoryFumblingTest(CoverageTest):
211225
"""Test that we properly manage the None refcount."""

0 commit comments

Comments
 (0)