|
19 | 19 | from aiohttp import Fingerprint, ServerFingerprintMismatch, hdrs, web
|
20 | 20 | from aiohttp.abc import AbstractResolver
|
21 | 21 | from aiohttp.client_exceptions import TooManyRedirects
|
| 22 | +from aiohttp.pytest_plugin import AiohttpClient, TestClient |
22 | 23 | from aiohttp.test_utils import unused_port
|
23 | 24 |
|
24 | 25 |
|
@@ -3186,7 +3187,40 @@ async def handler(request):
|
3186 | 3187 | await client.get("/")
|
3187 | 3188 |
|
3188 | 3189 |
|
3189 |
| -async def test_read_timeout_on_prepared_response(aiohttp_client) -> None: |
| 3190 | +async def test_read_timeout_closes_connection(aiohttp_client: AiohttpClient) -> None: |
| 3191 | + request_count = 0 |
| 3192 | + |
| 3193 | + async def handler(request): |
| 3194 | + nonlocal request_count |
| 3195 | + request_count += 1 |
| 3196 | + if request_count < 3: |
| 3197 | + await asyncio.sleep(0.5) |
| 3198 | + return web.Response(body=f"request:{request_count}") |
| 3199 | + |
| 3200 | + app = web.Application() |
| 3201 | + app.add_routes([web.get("/", handler)]) |
| 3202 | + |
| 3203 | + timeout = aiohttp.ClientTimeout(total=0.1) |
| 3204 | + client: TestClient = await aiohttp_client(app, timeout=timeout) |
| 3205 | + with pytest.raises(asyncio.TimeoutError): |
| 3206 | + await client.get("/") |
| 3207 | + |
| 3208 | + # Make sure its really closed |
| 3209 | + assert not client.session.connector._conns |
| 3210 | + |
| 3211 | + with pytest.raises(asyncio.TimeoutError): |
| 3212 | + await client.get("/") |
| 3213 | + |
| 3214 | + # Make sure its really closed |
| 3215 | + assert not client.session.connector._conns |
| 3216 | + result = await client.get("/") |
| 3217 | + assert await result.read() == b"request:3" |
| 3218 | + |
| 3219 | + # Make sure its not closed |
| 3220 | + assert client.session.connector._conns |
| 3221 | + |
| 3222 | + |
| 3223 | +async def test_read_timeout_on_prepared_response(aiohttp_client: Any) -> None: |
3190 | 3224 | async def handler(request):
|
3191 | 3225 | resp = aiohttp.web.StreamResponse()
|
3192 | 3226 | await resp.prepare(request)
|
|
0 commit comments