fix: shield lifespan teardown from cancellation (#3480)

* fix: shield lifespan teardown from cancellation

Co-authored-by: Claude <noreply@anthropic.com>

* fix: stabilize flaky task and timeout tests under parallel execution

Co-authored-by: Claude <noreply@anthropic.com>

---------

Co-authored-by: Claude <noreply@anthropic.com>
This commit is contained in:
Jeremiah Lowin 2026-03-13 18:47:42 -05:00 committed by GitHub
commit 24d7aefe28
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
6 changed files with 180 additions and 31 deletions

View file

@ -1,7 +1,5 @@
"""Client timeout tests."""
import sys
import pytest
from mcp import McpError
@ -36,15 +34,11 @@ class TestTimeout:
with pytest.raises(McpError):
await client.call_tool("sleep", {"seconds": 0.1}, timeout=0.01)
@pytest.mark.skipif(
sys.platform == "win32",
reason="This test is flaky on Windows. Sometimes the client timeout is respected and sometimes it is not.",
)
async def test_timeout_tool_call_overrides_client_timeout_even_if_lower(
self, fastmcp_server: FastMCP
):
async with Client(
transport=FastMCPTransport(fastmcp_server),
timeout=0.01,
timeout=0.1,
) as client:
await client.call_tool("sleep", {"seconds": 0.1}, timeout=2)
await client.call_tool("sleep", {"seconds": 0.5}, timeout=2)