Skip to content

Commit

Permalink
Add a test for failure cases
Browse files Browse the repository at this point in the history
  • Loading branch information
MtkN1 committed May 4, 2024
1 parent f8955fe commit aa27ad2
Showing 1 changed file with 8 additions and 4 deletions.
12 changes: 8 additions & 4 deletions tests/test_ws.py
Original file line number Diff line number Diff line change
Expand Up @@ -398,7 +398,7 @@ async def echo_json(request: web.Request):
pass
else:
await ws.pong(msg.data)
await ws.send_str("pong")
await ws.send_json({"data": "spam"})
elif msg.type == aiohttp.WSMsgType.PONG:
continue

Expand All @@ -413,14 +413,16 @@ async def echo_json(request: web.Request):


@pytest.mark.asyncio
async def test_websocketapp_ensure_open(test_ping_pong_server: TestServer):
async def test_websocketapp_ensure_open_hdlr(
test_ping_pong_server: TestServer, caplog: pytest.LogCaptureFixture
):
wsq = pybotters.WebSocketQueue()

async def message_ping_pong():
async with pybotters.Client() as client:
ws = await client.ws_connect(
f"ws://localhost:{test_ping_pong_server.port}/ws",
hdlr_str=wsq.onmessage,
hdlr_json=wsq.onmessage,
heartbeat=None,
autoping=True,
)
Expand All @@ -434,9 +436,11 @@ async def message_ping_pong():
wstask.cancel()
await asyncio.wait([wstask], timeout=5.0)

assert received_messages == ["pong"]
assert received_messages == [{"data": "spam"}]
assert wstask.cancelled()

assert caplog.records == [] # No handler errors


def test_heartbeathosts():
assert hasattr(pybotters.ws.HeartbeatHosts, "items")
Expand Down

0 comments on commit aa27ad2

Please sign in to comment.