Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[PR #10577/3c60cd22 backport][3.12] Parametrize leak tests #10581

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
47 changes: 21 additions & 26 deletions tests/test_leaks.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,34 +9,29 @@


@pytest.mark.skipif(IS_PYPY, reason="gc.DEBUG_LEAK not available on PyPy")
def test_client_response_does_not_leak_on_server_disconnected_error() -> None:
"""Test that ClientResponse is collected after server disconnects.

https://github.com/aio-libs/aiohttp/issues/10535
"""
leak_test_script = pathlib.Path(__file__).parent.joinpath(
"isolated", "check_for_client_response_leak.py"
)

with subprocess.Popen(
[sys.executable, "-u", str(leak_test_script)],
stdout=subprocess.PIPE,
) as proc:
assert proc.wait() == 0, "ClientResponse leaked"


@pytest.mark.skipif(IS_PYPY, reason="gc.DEBUG_LEAK not available on PyPy")
def test_request_does_not_leak_when_request_handler_raises() -> None:
"""Test that the Request object is collected when the handler raises.

https://github.com/aio-libs/aiohttp/issues/10548
"""
leak_test_script = pathlib.Path(__file__).parent.joinpath(
"isolated", "check_for_request_leak.py"
)
@pytest.mark.parametrize(
("script", "message"),
[
(
# Test that ClientResponse is collected after server disconnects.
# https://github.com/aio-libs/aiohttp/issues/10535
"check_for_client_response_leak.py",
"ClientResponse leaked",
),
(
# Test that Request object is collected when the handler raises.
# https://github.com/aio-libs/aiohttp/issues/10548
"check_for_request_leak.py",
"Request leaked",
),
],
)
def test_leak(script: str, message: str) -> None:
"""Run isolated leak test script and check for leaks."""
leak_test_script = pathlib.Path(__file__).parent.joinpath("isolated", script)

with subprocess.Popen(
[sys.executable, "-u", str(leak_test_script)],
stdout=subprocess.PIPE,
) as proc:
assert proc.wait() == 0, "Request leaked"
assert proc.wait() == 0, message
Loading