-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
adding exception handling for room start tasks
- Loading branch information
Jialin Zhang
committed
Apr 26, 2024
1 parent
fd7c0b5
commit 1f2a11c
Showing
2 changed files
with
89 additions
and
30 deletions.
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,33 @@ | ||
import pytest | ||
from anyio import TASK_STATUS_IGNORED, sleep | ||
from anyio.abc import TaskStatus | ||
from pycrdt import Map | ||
|
||
from pycrdt_websocket import exception_logger | ||
from pycrdt_websocket.yroom import YRoom | ||
|
||
pytestmark = pytest.mark.anyio | ||
|
||
|
||
@pytest.mark.parametrize("websocket_server_api", ["websocket_server_start_stop"], indirect=True) | ||
@pytest.mark.parametrize("yws_server", [{"exception_handler": exception_logger}], indirect=True) | ||
async def test_yroom_restart(yws_server, yws_provider): | ||
port, server = yws_server | ||
yroom = YRoom(exception_handler=exception_logger) | ||
|
||
async def raise_error(task_status: TaskStatus[None] = TASK_STATUS_IGNORED): | ||
task_status.started() | ||
raise RuntimeError("foo") | ||
|
||
yroom.ydoc = yws_provider | ||
await server.start_room(yroom) | ||
yroom.ydoc["map"] = ymap1 = Map() | ||
ymap1["key"] = "value" | ||
task_group_1 = yroom._task_group | ||
await yroom._task_group.start(raise_error) | ||
ymap1["key2"] = "value2" | ||
await sleep(0.1) | ||
assert yroom._task_group is not task_group_1 | ||
assert yroom._task_group is not None | ||
assert not yroom._task_group.cancel_scope.cancel_called | ||
await yroom.stop() |