Skip to content

Commit fe49931

Browse files
committed
try to check notification event received
1 parent 24553c6 commit fe49931

File tree

1 file changed

+9
-0
lines changed

1 file changed

+9
-0
lines changed

tests/shared/test_session.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,6 +50,7 @@ async def test_request_cancellation():
5050

5151
ev_tool_called = anyio.Event()
5252
ev_cancelled = anyio.Event()
53+
ev_cancel_notified = anyio.Event()
5354
request_id = None
5455

5556
# Start the request in a separate task so we can cancel it
@@ -66,6 +67,11 @@ async def handle_call_tool(name: str, arguments: dict | None) -> list:
6667
await anyio.sleep(10) # Long enough to ensure we can cancel
6768
return []
6869
raise ValueError(f"Unknown tool: {name}")
70+
71+
@server.cancel_notification()
72+
async def handle_cancel(requestId: str | int, reason: str | None):
73+
nonlocal ev_cancel_notified
74+
ev_cancel_notified.set()
6975

7076
# Register the tool so it shows up in list_tools
7177
@server.list_tools()
@@ -121,6 +127,9 @@ async def make_request(client_session):
121127
)
122128
)
123129

130+
with anyio.fail_after(1):
131+
await ev_cancel_notified.wait()
132+
124133
# Give cancellation time to process
125134
with anyio.fail_after(1):
126135
await ev_cancelled.wait()

0 commit comments

Comments
 (0)