Skip to content

Commit

Permalink
adjust leak test for jit
Browse files Browse the repository at this point in the history
  • Loading branch information
davidism committed May 11, 2024
1 parent a46facc commit 09ec048
Showing 1 changed file with 8 additions and 14 deletions.
22 changes: 8 additions & 14 deletions tests/test_leak.py
Original file line number Diff line number Diff line change
@@ -1,31 +1,25 @@
from __future__ import annotations

import gc
import platform

import pytest

from markupsafe import _escape_inner # type: ignore[attr-defined]
from markupsafe import escape


@pytest.mark.skipif(
_escape_inner.__module__ == "markupsafe._native",
reason="only test memory leak with speedups",
)
def test_markup_leaks() -> None:
counts = set()
# Try to start with a "clean" count. Works for PyPy but not 3.13 JIT.
gc.collect()

for _i in range(20):
for _j in range(1000):
for _ in range(20):
for _ in range(1000):
escape("foo")
escape("<foo>")
escape("foo")
escape("<foo>")

if platform.python_implementation() == "PyPy":
gc.collect()

counts.add(len(gc.get_objects()))

assert len(counts) == 1
# Some implementations, such as PyPy and Python 3.13 JIT, end up with 2
# counts rather than one. Presumably this is internals stabilizing. A leak
# would presumably have a different count every loop.
assert len(counts) < 2

0 comments on commit 09ec048

Please sign in to comment.