Skip to content

Commit

Permalink
Fix a test that was leaving unprocessed tasks after the test
Browse files Browse the repository at this point in the history
The request was cancelled fast enough, and the response writer was closed. But the response handler continued to try writing to that closed transport if not cancelled fast enough. Now, it will ignore such writing errors too.

Signed-off-by: Sergey Vasilyev <[email protected]>
  • Loading branch information
nolar committed Oct 2, 2022
1 parent b7f8f0b commit c864105
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions tests/apis/test_api_requests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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)

Expand Down

0 comments on commit c864105

Please sign in to comment.