Skip to content
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
17 changes: 9 additions & 8 deletions tests/test_client_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -4326,14 +4326,12 @@ async def handler(request: web.Request) -> NoReturn:


async def test_read_timeout_closes_connection(aiohttp_client: AiohttpClient) -> None:
request_count = 0
slow = True

async def handler(request: web.Request) -> web.Response:
nonlocal request_count
request_count += 1
if request_count < 3:
if slow:
await asyncio.sleep(0.5)
return web.Response(body=f"request:{request_count}")
return web.Response(body=b"done")

app = web.Application()
app.add_routes([web.get("/", handler)])
Expand All @@ -4352,10 +4350,13 @@ async def handler(request: web.Request) -> web.Response:

# Make sure its really closed
assert not client.session.connector._conns
# This request works (handler responds instantly); override the tight
# session timeout so slow CI can't flake the round trip on a new connection.
# A client-side timeout doesn't guarantee the handler ever ran (the
# timeout can fire before the request is dispatched on a slow CI run),
# so switch behaviour with the flag instead of counting invocations, and
# override the tight session timeout so the round trip can't flake either.
slow = False
async with client.get("/", timeout=aiohttp.ClientTimeout(total=10)) as result:
assert await result.read() == b"request:3"
assert await result.read() == b"done"

# Make sure its not closed
assert client.session.connector._conns
Expand Down
Loading