Skip to content

Commit 1f677a9

Browse files
Fix Flaky test.
Removed usage of snapshot in parametrised test as they don't work well together and end up failing the test.
1 parent 8fa013c commit 1f677a9

File tree

2 files changed

+17
-11
lines changed

2 files changed

+17
-11
lines changed

tests/client/test_auth.py

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@
1010

1111
import httpx
1212
import pytest
13-
from inline_snapshot import snapshot
1413
from pydantic import AnyHttpUrl
1514

1615
from mcp.client.auth import OAuthClientProvider
@@ -968,8 +967,7 @@ def test_build_metadata(
968967
revocation_options=RevocationOptions(enabled=True),
969968
)
970969

971-
assert metadata == snapshot(
972-
OAuthMetadata(
970+
assert metadata == OAuthMetadata(
973971
issuer=AnyHttpUrl(issuer_url),
974972
authorization_endpoint=AnyHttpUrl(authorization_endpoint),
975973
token_endpoint=AnyHttpUrl(token_endpoint),
@@ -982,4 +980,3 @@ def test_build_metadata(
982980
revocation_endpoint_auth_methods_supported=["client_secret_post"],
983981
code_challenge_methods_supported=["S256"],
984982
)
985-
)

tests/issues/test_188_concurrency.py

Lines changed: 16 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -14,29 +14,38 @@
1414
@pytest.mark.anyio
1515
async def test_messages_are_executed_concurrently():
1616
server = FastMCP("test")
17-
17+
call_timestamps = []
18+
1819
@server.tool("sleep")
1920
async def sleep_tool():
21+
call_timestamps.append(("tool_start_time", anyio.current_time()))
2022
await anyio.sleep(_sleep_time_seconds)
23+
call_timestamps.append(("tool_end_time", anyio.current_time()))
2124
return "done"
2225

2326
@server.resource(_resource_name)
2427
async def slow_resource():
28+
call_timestamps.append(("resource_start_time", anyio.current_time()))
2529
await anyio.sleep(_sleep_time_seconds)
30+
call_timestamps.append(("resource_end_time", anyio.current_time()))
2631
return "slow"
2732

2833
async with create_session(server._mcp_server) as client_session:
29-
start_time = anyio.current_time()
3034
async with anyio.create_task_group() as tg:
3135
for _ in range(10):
3236
tg.start_soon(client_session.call_tool, "sleep")
3337
tg.start_soon(client_session.read_resource, AnyUrl(_resource_name))
3438

35-
end_time = anyio.current_time()
36-
37-
duration = end_time - start_time
38-
assert duration < 6 * _sleep_time_seconds
39-
print(duration)
39+
active_calls = 0
40+
max_concurrent_calls = 0
41+
for call_type, _ in sorted(call_timestamps, key=lambda x: x[1]):
42+
if "start" in call_type:
43+
active_calls += 1
44+
max_concurrent_calls = max(max_concurrent_calls, active_calls)
45+
else:
46+
active_calls -= 1
47+
print(f"Max concurrent calls: {max_concurrent_calls}")
48+
assert max_concurrent_calls > 1, "No concurrent calls were executed"
4049

4150

4251
def main():

0 commit comments

Comments
 (0)