Skip to content

Commit

Permalink
Check the disconncet code
Browse files Browse the repository at this point in the history
  • Loading branch information
Kludex committed Nov 1, 2022
1 parent e562633 commit 04277bd
Showing 1 changed file with 7 additions and 0 deletions.
7 changes: 7 additions & 0 deletions tests/protocols/test_websocket.py
Expand Up @@ -732,6 +732,7 @@ async def test_server_can_read_messages_in_buffer_after_close(
):
frames = []
client_close_connection = asyncio.Event()
disconnect_message = {}

class App(WebSocketResponse):
async def websocket_connect(self, message):
Expand All @@ -741,6 +742,10 @@ async def websocket_connect(self, message):
# read these frames
await client_close_connection.wait()

async def websocket_disconnect(self, message):
nonlocal disconnect_message
disconnect_message = message

async def websocket_receive(self, message):
frames.append(message.get("bytes"))

Expand All @@ -753,9 +758,11 @@ async def send_text(url):
config = Config(app=App, ws=ws_protocol_cls, http=http_protocol_cls, lifespan="off")
async with run_server(config):
await send_text("ws://127.0.0.1:8000")
await asyncio.sleep(0.1)
client_close_connection.set()

assert frames == [b"abc", b"abc", b"abc"]
assert disconnect_message == {"type": "websocket.disconnect", "code": 1000}


@pytest.mark.anyio
Expand Down

0 comments on commit 04277bd

Please sign in to comment.