|
5 | 5 | import pytest |
6 | 6 |
|
7 | 7 | import aiohttp |
8 | | -from aiohttp import hdrs, web |
| 8 | +from aiohttp import ServerTimeoutError, WSMsgType, hdrs, web |
9 | 9 | from aiohttp.http import WSCloseCode |
10 | 10 | from aiohttp.pytest_plugin import AiohttpClient |
11 | 11 |
|
@@ -624,7 +624,35 @@ async def handler(request): |
624 | 624 | assert resp.close_code is WSCloseCode.ABNORMAL_CLOSURE |
625 | 625 |
|
626 | 626 |
|
627 | | -async def test_send_recv_compress(aiohttp_client) -> None: |
| 627 | +async def test_heartbeat_no_pong_concurrent_receive(aiohttp_client: Any) -> None: |
| 628 | + ping_received = False |
| 629 | + |
| 630 | + async def handler(request): |
| 631 | + nonlocal ping_received |
| 632 | + ws = web.WebSocketResponse(autoping=False) |
| 633 | + await ws.prepare(request) |
| 634 | + msg = await ws.receive() |
| 635 | + ping_received = msg.type is aiohttp.WSMsgType.PING |
| 636 | + ws._reader.feed_eof = lambda: None |
| 637 | + await asyncio.sleep(10.0) |
| 638 | + |
| 639 | + app = web.Application() |
| 640 | + app.router.add_route("GET", "/", handler) |
| 641 | + |
| 642 | + client = await aiohttp_client(app) |
| 643 | + resp = await client.ws_connect("/", heartbeat=0.1) |
| 644 | + resp._reader.feed_eof = lambda: None |
| 645 | + |
| 646 | + # Connection should be closed roughly after 1.5x heartbeat. |
| 647 | + msg = await resp.receive(5.0) |
| 648 | + assert ping_received |
| 649 | + assert resp.close_code is WSCloseCode.ABNORMAL_CLOSURE |
| 650 | + assert msg |
| 651 | + assert msg.type is WSMsgType.ERROR |
| 652 | + assert isinstance(msg.data, ServerTimeoutError) |
| 653 | + |
| 654 | + |
| 655 | +async def test_send_recv_compress(aiohttp_client: Any) -> None: |
628 | 656 | async def handler(request): |
629 | 657 | ws = web.WebSocketResponse() |
630 | 658 | await ws.prepare(request) |
|
0 commit comments