Skip to content

Commit 9bee1d9

Browse files
Test fixes for v1.7.x (#684)
1 parent ba04a0f commit 9bee1d9

File tree

2 files changed

+28
-8
lines changed

2 files changed

+28
-8
lines changed

tests/issues/test_188_concurrency.py

+20-6
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,43 @@
1414
@pytest.mark.anyio
1515
async def test_messages_are_executed_concurrently():
1616
server = FastMCP("test")
17+
call_timestamps = []
1718

1819
@server.tool("sleep")
1920
async def sleep_tool():
21+
start_time = anyio.current_time()
22+
call_timestamps.append(("tool_start", start_time))
2023
await anyio.sleep(_sleep_time_seconds)
24+
end_time = anyio.current_time()
25+
call_timestamps.append(("tool_end", end_time))
2126
return "done"
2227

2328
@server.resource(_resource_name)
2429
async def slow_resource():
30+
start_time = anyio.current_time()
31+
call_timestamps.append(("resource_start", start_time))
2532
await anyio.sleep(_sleep_time_seconds)
33+
end_time = anyio.current_time()
34+
call_timestamps.append(("resource_end", end_time))
2635
return "slow"
2736

2837
async with create_session(server._mcp_server) as client_session:
29-
start_time = anyio.current_time()
3038
async with anyio.create_task_group() as tg:
3139
for _ in range(10):
3240
tg.start_soon(client_session.call_tool, "sleep")
3341
tg.start_soon(client_session.read_resource, AnyUrl(_resource_name))
3442

35-
end_time = anyio.current_time()
36-
37-
duration = end_time - start_time
38-
assert duration < 3 * _sleep_time_seconds
39-
print(duration)
43+
# Verify concurrent execution by checking for overlapping calls
44+
active_calls = 0
45+
max_concurrent_calls = 0
46+
for call_type, timestamp in sorted(call_timestamps, key=lambda x: x[1]):
47+
if "start" in call_type:
48+
active_calls += 1
49+
max_concurrent_calls = max(max_concurrent_calls, active_calls)
50+
else:
51+
active_calls -= 1
52+
print(f"\nMax concurrent calls: {max_concurrent_calls}")
53+
assert max_concurrent_calls > 1, "No concurrent calls detected"
4054

4155

4256
def main():

tests/test_examples.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -69,8 +69,14 @@ async def test_desktop(monkeypatch):
6969
content = result.contents[0]
7070
assert isinstance(content, TextResourceContents)
7171
assert isinstance(content.text, str)
72-
assert "/fake/path/file1.txt" in content.text
73-
assert "/fake/path/file2.txt" in content.text
72+
assert any(
73+
path in content.text
74+
for path in ["/fake/path/file1.txt", "\\\\fake\\\\path\\\\file1.txt"]
75+
)
76+
assert any(
77+
path in content.text
78+
for path in ["/fake/path/file2.txt", "\\\\fake\\\\path\\\\file2.txt"]
79+
)
7480

7581

7682
@pytest.mark.parametrize("example", find_examples("README.md"), ids=str)

0 commit comments

Comments
 (0)