Spaces:
Running
Running
Sillocan commited on
Commit ·
d913408
1
Parent(s): f15abd4
test: Demonstrate issue with concurrent proxy tasks
Browse files- tests/server/test_proxy.py +24 -0
tests/server/test_proxy.py
CHANGED
|
@@ -3,6 +3,7 @@ from typing import Any
|
|
| 3 |
|
| 4 |
import mcp.types
|
| 5 |
import pytest
|
|
|
|
| 6 |
from dirty_equals import Contains
|
| 7 |
from mcp import McpError
|
| 8 |
|
|
@@ -242,3 +243,26 @@ class TestPrompts:
|
|
| 242 |
assert result.messages[0].role == "user"
|
| 243 |
assert isinstance(result.messages[0].content, mcp.types.TextContent)
|
| 244 |
assert result.messages[0].content.text == "Welcome to FastMCP, Alice!"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| 3 |
|
| 4 |
import mcp.types
|
| 5 |
import pytest
|
| 6 |
+
from anyio import create_task_group
|
| 7 |
from dirty_equals import Contains
|
| 8 |
from mcp import McpError
|
| 9 |
|
|
|
|
| 243 |
assert result.messages[0].role == "user"
|
| 244 |
assert isinstance(result.messages[0].content, mcp.types.TextContent)
|
| 245 |
assert result.messages[0].content.text == "Welcome to FastMCP, Alice!"
|
| 246 |
+
|
| 247 |
+
|
| 248 |
+
async def test_proxy_handles_multiple_concurrent_tasks_correctly(
|
| 249 |
+
proxy_server: FastMCPProxy,
|
| 250 |
+
):
|
| 251 |
+
results = {}
|
| 252 |
+
|
| 253 |
+
async def get_and_store(name, coro):
|
| 254 |
+
results[name] = await coro()
|
| 255 |
+
|
| 256 |
+
async with create_task_group() as tg:
|
| 257 |
+
tg.start_soon(get_and_store, "prompts", proxy_server.get_prompts)
|
| 258 |
+
tg.start_soon(get_and_store, "resources", proxy_server.get_resources)
|
| 259 |
+
tg.start_soon(get_and_store, "tools", proxy_server.get_tools)
|
| 260 |
+
|
| 261 |
+
assert list(results) == Contains("resources", "prompts", "tools")
|
| 262 |
+
assert list(results["prompts"]) == Contains("welcome")
|
| 263 |
+
assert [r.name for r in results["resources"].values()] == Contains(
|
| 264 |
+
"data://users", "resource://wave"
|
| 265 |
+
)
|
| 266 |
+
assert list(results["tools"]) == Contains(
|
| 267 |
+
"greet", "add", "error_tool", "tool_without_description"
|
| 268 |
+
)
|