@@ -28,8 +28,7 @@ async def test_notification_validation_error(tmp_path: Path):
28
28
29
29
server = Server (name = "test" )
30
30
request_count = 0
31
- slow_request_started = anyio .Event ()
32
- slow_request_complete = anyio .Event ()
31
+ slow_request_lock = anyio .Event ()
33
32
34
33
@server .list_tools ()
35
34
async def list_tools ()-> list [types .Tool ]:
@@ -52,16 +51,9 @@ async def slow_tool(name: str, arg) -> Sequence[ContentBlock]:
52
51
request_count += 1
53
52
54
53
if name == "slow" :
55
- # Signal that slow request has started
56
- slow_request_started .set ()
57
- # Long enough to ensure timeout
58
- await anyio .sleep (0.2 )
59
- # Signal completion
60
- slow_request_complete .set ()
54
+ await slow_request_lock .wait ()# it should timeout here
61
55
return [TextContent (type = "text" ,text = f"slow{ request_count } " )]
62
56
elif name == "fast" :
63
- # Fast enough to complete before timeout
64
- await anyio .sleep (0.01 )
65
57
return [TextContent (type = "text" ,text = f"fast{ request_count } " )]
66
58
return [TextContent (type = "text" ,text = f"unknown{ request_count } " )]
67
59
@@ -90,16 +82,15 @@ async def client(read_stream, write_stream, scope):
90
82
# First call should work (fast operation)
91
83
result = await session .call_tool ("fast" )
92
84
assert result .content == [TextContent (type = "text" ,text = "fast 1" )]
93
- assert not slow_request_complete .is_set ()
85
+ assert not slow_request_lock .is_set ()
94
86
95
87
# Second call should timeout (slow operation)
96
88
with pytest .raises (McpError )as exc_info :
97
89
await session .call_tool ("slow" )
98
90
assert "Timed out while waiting" in str (exc_info .value )
99
91
100
- # Wait for slow request to complete in the background
101
- with anyio .fail_after (1 ):# Timeout after 1 second
102
- await slow_request_complete .wait ()
92
+ # release the slow request not to have hanging process
93
+ slow_request_lock .set ()
103
94
104
95
# Third call should work (fast operation),
105
96
# proving server is still responsive