Skip to content

[PR #10981/2617ab23 backport][3.12] Fix flakey test_client_middleware_retry_reuses_connection test #10986

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

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
7 changes: 6 additions & 1 deletion tests/test_client_middleware.py
Original file line number Diff line number Diff line change
Expand Up @@ -863,8 +863,13 @@ async def test_client_middleware_retry_reuses_connection(
aiohttp_server: AiohttpServer,
) -> None:
"""Test that connections are reused when middleware performs retries."""
request_count = 0

async def handler(request: web.Request) -> web.Response:
nonlocal request_count
request_count += 1
if request_count == 1:
return web.Response(status=400) # First request returns 400 with no body
return web.Response(text="OK")

class TrackingConnector(TCPConnector):
Expand All @@ -891,7 +896,7 @@ async def __call__(
while True:
self.attempt_count += 1
response = await handler(request)
if retry_count == 0:
if response.status == 400 and retry_count == 0:
retry_count += 1
continue
return response
Expand Down
Loading