-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bugfix ensure websocket disconnect cancels the connection's tasks
The return would skip paste the cancel call, resulting in the nursery not being cancelled and hence the app potentially running after disconnection.
- Loading branch information
Showing
2 changed files
with
27 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
import pytest | ||
import trio | ||
|
||
from quart_trio.app import QuartTrio | ||
from quart_trio.asgi import TrioASGIWebsocketConnection | ||
|
||
|
||
@pytest.mark.trio | ||
async def test_websocket_complete_on_disconnect() -> None: | ||
scope = { | ||
"asgi": {"version": "3"}, | ||
"headers": [(b"host", b"quart")], | ||
"http_version": "1.1", | ||
"method": "GET", | ||
"scheme": "wss", | ||
"path": "ws://quart/path", | ||
"query_string": b"", | ||
"subprotocols": [], | ||
"extensions": {"websocket.http.response": {}}, | ||
} | ||
connection = TrioASGIWebsocketConnection(QuartTrio(__name__), scope) | ||
send_channel, receive_channel = trio.open_memory_channel(0) | ||
async with trio.open_nursery() as nursery: | ||
nursery.start_soon(connection.handle_messages, nursery, receive_channel.receive) | ||
await send_channel.send({"type": "websocket.disconnect"}) | ||
assert nursery.cancel_scope.cancelled_caught |