mirror of
https://github.com/PrefectHQ/fastmcp.git
synced 2026-08-25 06:54:19 +02:00
* 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>
44 lines
1.6 KiB
Python
44 lines
1.6 KiB
Python
"""Client timeout tests."""
|
|
|
|
import pytest
|
|
from mcp import McpError
|
|
|
|
from fastmcp.client import Client
|
|
from fastmcp.client.transports import FastMCPTransport
|
|
from fastmcp.server.server import FastMCP
|
|
|
|
|
|
class TestTimeout:
|
|
async def test_timeout(self, fastmcp_server: FastMCP):
|
|
async with Client(
|
|
transport=FastMCPTransport(fastmcp_server), timeout=0.05
|
|
) as client:
|
|
with pytest.raises(
|
|
McpError,
|
|
match="Timed out while waiting for response to ClientRequest. Waited 0.05 seconds",
|
|
):
|
|
await client.call_tool("sleep", {"seconds": 0.1})
|
|
|
|
async def test_timeout_tool_call(self, fastmcp_server: FastMCP):
|
|
async with Client(transport=FastMCPTransport(fastmcp_server)) as client:
|
|
with pytest.raises(McpError):
|
|
await client.call_tool("sleep", {"seconds": 0.1}, timeout=0.01)
|
|
|
|
async def test_timeout_tool_call_overrides_client_timeout(
|
|
self, fastmcp_server: FastMCP
|
|
):
|
|
async with Client(
|
|
transport=FastMCPTransport(fastmcp_server),
|
|
timeout=2,
|
|
) as client:
|
|
with pytest.raises(McpError):
|
|
await client.call_tool("sleep", {"seconds": 0.1}, timeout=0.01)
|
|
|
|
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.1,
|
|
) as client:
|
|
await client.call_tool("sleep", {"seconds": 0.5}, timeout=2)
|