Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.6] Refactor the test to fail instead of hanging (#4225) #4229

Merged
merged 1 commit into from
Oct 18, 2019
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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