Skip to content

Test fixes for v1.7.x #684

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 5 commits into from
May 12, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 20 additions & 6 deletions tests/issues/test_188_concurrency.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,29 +14,43 @@
@pytest.mark.anyio
async def test_messages_are_executed_concurrently():
server = FastMCP("test")
call_timestamps = []

@server.tool("sleep")
async def sleep_tool():
start_time = anyio.current_time()
call_timestamps.append(("tool_start", start_time))
await anyio.sleep(_sleep_time_seconds)
end_time = anyio.current_time()
call_timestamps.append(("tool_end", end_time))
return "done"

@server.resource(_resource_name)
async def slow_resource():
start_time = anyio.current_time()
call_timestamps.append(("resource_start", start_time))
await anyio.sleep(_sleep_time_seconds)
end_time = anyio.current_time()
call_timestamps.append(("resource_end", end_time))
return "slow"

async with create_session(server._mcp_server) as client_session:
start_time = anyio.current_time()
async with anyio.create_task_group() as tg:
for _ in range(10):
tg.start_soon(client_session.call_tool, "sleep")
tg.start_soon(client_session.read_resource, AnyUrl(_resource_name))

end_time = anyio.current_time()

duration = end_time - start_time
assert duration < 3 * _sleep_time_seconds
print(duration)
# Verify concurrent execution by checking for overlapping calls
active_calls = 0
max_concurrent_calls = 0
for call_type, timestamp in sorted(call_timestamps, key=lambda x: x[1]):
if "start" in call_type:
active_calls += 1
max_concurrent_calls = max(max_concurrent_calls, active_calls)
else:
active_calls -= 1
print(f"\nMax concurrent calls: {max_concurrent_calls}")
assert max_concurrent_calls > 1, "No concurrent calls detected"


def main():
Expand Down
10 changes: 8 additions & 2 deletions tests/test_examples.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,8 +69,14 @@ async def test_desktop(monkeypatch):
content = result.contents[0]
assert isinstance(content, TextResourceContents)
assert isinstance(content.text, str)
assert "/fake/path/file1.txt" in content.text
assert "/fake/path/file2.txt" in content.text
assert any(
path in content.text
for path in ["/fake/path/file1.txt", "\\\\fake\\\\path\\\\file1.txt"]
)
assert any(
path in content.text
for path in ["/fake/path/file2.txt", "\\\\fake\\\\path\\\\file2.txt"]
)


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