From 82c961d631bd698bd697a5bd91dfdcced8b6a9d0 Mon Sep 17 00:00:00 2001 From: ihrpr Date: Fri, 18 Jul 2025 16:11:33 +0100 Subject: [PATCH 1/2] fix flaky test --- tests/issues/test_88_random_error.py | 19 +++++-------------- 1 file changed, 5 insertions(+), 14 deletions(-) diff --git a/tests/issues/test_88_random_error.py b/tests/issues/test_88_random_error.py index d595ed022..e3bf9e400 100644 --- a/tests/issues/test_88_random_error.py +++ b/tests/issues/test_88_random_error.py @@ -28,8 +28,7 @@ async def test_notification_validation_error(tmp_path: Path): server = Server(name="test") request_count = 0 - slow_request_started = anyio.Event() - slow_request_complete = anyio.Event() + slow_request = anyio.Event() @server.list_tools() async def list_tools() -> list[types.Tool]: @@ -52,16 +51,9 @@ async def slow_tool(name: str, arg) -> Sequence[ContentBlock]: request_count += 1 if name == "slow": - # Signal that slow request has started - slow_request_started.set() - # Long enough to ensure timeout - await anyio.sleep(0.2) - # Signal completion - slow_request_complete.set() + await slow_request.wait() # it should timeout here return [TextContent(type="text", text=f"slow {request_count}")] elif name == "fast": - # Fast enough to complete before timeout - await anyio.sleep(0.01) return [TextContent(type="text", text=f"fast {request_count}")] return [TextContent(type="text", text=f"unknown {request_count}")] @@ -90,16 +82,15 @@ async def client(read_stream, write_stream, scope): # First call should work (fast operation) result = await session.call_tool("fast") assert result.content == [TextContent(type="text", text="fast 1")] - assert not slow_request_complete.is_set() + assert not slow_request.is_set() # Second call should timeout (slow operation) with pytest.raises(McpError) as exc_info: await session.call_tool("slow") assert "Timed out while waiting" in str(exc_info.value) - # Wait for slow request to complete in the background - with anyio.fail_after(1): # Timeout after 1 second - await slow_request_complete.wait() + # release the slow request not to have hagning process + slow_request.set() # Third call should work (fast operation), # proving server is still responsive From eeca507e53dca8a47a6650f154a25235257e4d91 Mon Sep 17 00:00:00 2001 From: ihrpr Date: Fri, 18 Jul 2025 16:18:47 +0100 Subject: [PATCH 2/2] typos --- tests/issues/test_88_random_error.py | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/tests/issues/test_88_random_error.py b/tests/issues/test_88_random_error.py index e3bf9e400..c3570a39c 100644 --- a/tests/issues/test_88_random_error.py +++ b/tests/issues/test_88_random_error.py @@ -28,7 +28,7 @@ async def test_notification_validation_error(tmp_path: Path): server = Server(name="test") request_count = 0 - slow_request = anyio.Event() + slow_request_lock = anyio.Event() @server.list_tools() async def list_tools() -> list[types.Tool]: @@ -51,7 +51,7 @@ async def slow_tool(name: str, arg) -> Sequence[ContentBlock]: request_count += 1 if name == "slow": - await slow_request.wait() # it should timeout here + await slow_request_lock.wait() # it should timeout here return [TextContent(type="text", text=f"slow {request_count}")] elif name == "fast": return [TextContent(type="text", text=f"fast {request_count}")] @@ -82,15 +82,15 @@ async def client(read_stream, write_stream, scope): # First call should work (fast operation) result = await session.call_tool("fast") assert result.content == [TextContent(type="text", text="fast 1")] - assert not slow_request.is_set() + assert not slow_request_lock.is_set() # Second call should timeout (slow operation) with pytest.raises(McpError) as exc_info: await session.call_tool("slow") assert "Timed out while waiting" in str(exc_info.value) - # release the slow request not to have hagning process - slow_request.set() + # release the slow request not to have hanging process + slow_request_lock.set() # Third call should work (fast operation), # proving server is still responsive