Skip to content

Commit 27ee4ff

Browse files
committed
test: free-threading builds were failing the old leak test #1924
This is a subtler check for leaks, and still clearly distinguishes between the broken code and the fixed code.
1 parent f473b87 commit 27ee4ff

File tree

1 file changed

+14
-6
lines changed

1 file changed

+14
-6
lines changed

tests/test_oddball.py

+14-6
Original file line numberDiff line numberDiff line change
@@ -209,17 +209,25 @@ def once(x): # line 301
209209
@pytest.mark.skipif(not testenv.C_TRACER, reason="Only the C tracer has refcounting issues")
210210
# In fact, sysmon explicitly holds onto all code objects,
211211
# so this will definitely fail with sysmon.
212-
def test_eval_codeobject_leak(self) -> None:
212+
@pytest.mark.parametrize("branch", [False, True])
213+
def test_eval_codeobject_leak(self, branch: bool) -> None:
213214
# https://github.com/nedbat/coveragepy/issues/1924
214215
code = """\
215-
for i in range(100_000):
216+
for i in range(10_000):
216217
r = eval("'a' + '1'")
217218
assert r == 'a1'
218219
"""
219-
ram_0 = osinfo.process_ram()
220-
self.check_coverage(code, [1, 2, 3], "")
221-
ram_growth = osinfo.process_ram() - ram_0
222-
assert ram_growth < 2_000 * 1024
220+
# Looking for leaks is hard. We consider the leak fixed if at least
221+
# one of our loops only increased the footprint by a small amount.
222+
base = osinfo.process_ram()
223+
deltas = []
224+
for _ in range(10):
225+
self.check_coverage(code, [1, 2, 3], "", branch=branch)
226+
now = osinfo.process_ram()
227+
deltas.append(now - base)
228+
print(f"Mem delta: {(now - base)//1024}")
229+
base = now
230+
assert any(d < 50 * 1024 for d in deltas)
223231

224232

225233
class MemoryFumblingTest(CoverageTest):

0 commit comments

Comments
 (0)