diff --git a/tests/apis/test_api_requests.py b/tests/apis/test_api_requests.py index ea2aa9de..3a30cfc9 100644 --- a/tests/apis/test_api_requests.py +++ b/tests/apis/test_api_requests.py @@ -236,15 +236,19 @@ async def serve_slowly(): async def test_stopper_in_streams( resp_mocker, aresponses, hostname, method, delay, expected, settings, logger): - async def stream_slowly(request: aiohttp.ClientRequest): + async def stream_slowly(request: aiohttp.web.Request) -> aiohttp.web.StreamResponse: response = aiohttp.web.StreamResponse() await response.prepare(request) - await asyncio.sleep(0.05) - await response.write(b'{"fake": "result1"}\n') - await asyncio.sleep(0.15) - await response.write(b'{"fake": "result2"}\n') - await response.write_eof() - return response + try: + await asyncio.sleep(0.05) + await response.write(b'{"fake": "result1"}\n') + await asyncio.sleep(0.15) + await response.write(b'{"fake": "result2"}\n') + await response.write_eof() + except ConnectionError: + pass # usually when the client cancelled the request and closed the connection + finally: + return response aresponses.add(hostname, '/url', method, stream_slowly)