Skip to content

Commit

Permalink
Refactor the test to fail instead of hanging (#4225)
Browse files Browse the repository at this point in the history
  • Loading branch information
asvetlov authored Oct 18, 2019
1 parent f79f513 commit c7d841d
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions tests/test_web_websocket_functional.py
Original file line number Diff line number Diff line change
Expand Up @@ -246,18 +246,17 @@ async def handler(request):

async def test_close_timeout(loop, aiohttp_client) -> None:
aborted = loop.create_future()
elapsed = 1e10 # something big

async def handler(request):
nonlocal elapsed
ws = web.WebSocketResponse(timeout=0.1)
await ws.prepare(request)
assert 'request' == (await ws.receive_str())
await ws.send_str('reply')
begin = ws._loop.time()
assert (await ws.close())
elapsed = ws._loop.time() - begin
assert elapsed < 0.201, \
'close() should have returned before ' \
'at most 2x timeout.'
assert ws.close_code == 1006
assert isinstance(ws.exception(), asyncio.TimeoutError)
aborted.set_result(1)
Expand All @@ -281,6 +280,10 @@ async def handler(request):
await asyncio.sleep(0.08)
assert (await aborted)

assert elapsed < 0.201, \
'close() should have returned before ' \
'at most 2x timeout.'

await ws.close()


Expand Down

0 comments on commit c7d841d

Please sign in to comment.