Skip to content

Commit

Permalink
test: free-threading builds were failing the old leak test #1924
Browse files Browse the repository at this point in the history
This is a subtler check for leaks, and still clearly distinguishes
between the broken code and the fixed code.
  • Loading branch information
nedbat committed Feb 8, 2025
1 parent f473b87 commit 27ee4ff
Showing 1 changed file with 14 additions and 6 deletions.
20 changes: 14 additions & 6 deletions tests/test_oddball.py
Original file line number Diff line number Diff line change
Expand Up @@ -209,17 +209,25 @@ def once(x): # line 301
@pytest.mark.skipif(not testenv.C_TRACER, reason="Only the C tracer has refcounting issues")
# In fact, sysmon explicitly holds onto all code objects,
# so this will definitely fail with sysmon.
def test_eval_codeobject_leak(self) -> None:
@pytest.mark.parametrize("branch", [False, True])
def test_eval_codeobject_leak(self, branch: bool) -> None:
# https://github.com/nedbat/coveragepy/issues/1924
code = """\
for i in range(100_000):
for i in range(10_000):
r = eval("'a' + '1'")
assert r == 'a1'
"""
ram_0 = osinfo.process_ram()
self.check_coverage(code, [1, 2, 3], "")
ram_growth = osinfo.process_ram() - ram_0
assert ram_growth < 2_000 * 1024
# Looking for leaks is hard. We consider the leak fixed if at least
# one of our loops only increased the footprint by a small amount.
base = osinfo.process_ram()
deltas = []
for _ in range(10):
self.check_coverage(code, [1, 2, 3], "", branch=branch)
now = osinfo.process_ram()
deltas.append(now - base)
print(f"Mem delta: {(now - base)//1024}")
base = now
assert any(d < 50 * 1024 for d in deltas)


class MemoryFumblingTest(CoverageTest):
Expand Down

0 comments on commit 27ee4ff

Please sign in to comment.