Skip to content

Commit

Permalink
[3.6] Refactor the test to fail instead of hanging (#4225) (#4229)
Browse files Browse the repository at this point in the history
(cherry picked from commit c7d841d)

Co-authored-by: Andrew Svetlov <andrew.svetlov@gmail.com>
  • Loading branch information
asvetlov authored Oct 18, 2019
1 parent 529e760 commit c7eb6cf
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 Down Expand Up @@ -294,6 +293,10 @@ async def handler(request):
await asyncio.sleep(0.08, loop=loop)
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 c7eb6cf

Please sign in to comment.