From 379d3c1dd115ffec19b8f6dcdd14197e9b33eb3f Mon Sep 17 00:00:00 2001 From: Aishwarya Date: Sun, 11 May 2025 11:57:17 +0545 Subject: [PATCH 1/5] Fixing tests for Windows TESTED=all tests passing --- tests/test_examples.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/tests/test_examples.py b/tests/test_examples.py index c5e8ec9d74..9a9103b96f 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -69,8 +69,8 @@ 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) From 488d8678ea05ee9451e1d0447fe90f4bc9f3f703 Mon Sep 17 00:00:00 2001 From: Aishwarya Date: Sun, 11 May 2025 12:03:20 +0545 Subject: [PATCH 2/5] Linting fixes --- tests/test_examples.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/tests/test_examples.py b/tests/test_examples.py index 9a9103b96f..d145b6bae3 100644 --- a/tests/test_examples.py +++ b/tests/test_examples.py @@ -69,8 +69,14 @@ async def test_desktop(monkeypatch): content = result.contents[0] assert isinstance(content, TextResourceContents) assert isinstance(content.text, str) - 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"]) + 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) From febd21560865bf59c6933c193cc868319cef56b7 Mon Sep 17 00:00:00 2001 From: Aishwarya Date: Sun, 11 May 2025 14:28:12 +0545 Subject: [PATCH 3/5] Fix for flaky test case: tests/issues/test_messages_are_executed_concurrently.py Calculating number of concurrent calls by tracking start and end time. TESTED=all existing test cases passed. --- tests/issues/test_188_concurrency.py | 25 ++++++++++++++++++++----- 1 file changed, 20 insertions(+), 5 deletions(-) diff --git a/tests/issues/test_188_concurrency.py b/tests/issues/test_188_concurrency.py index 2aa6c49cb3..7fc18aa102 100644 --- a/tests/issues/test_188_concurrency.py +++ b/tests/issues/test_188_concurrency.py @@ -14,15 +14,24 @@ @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: @@ -32,11 +41,17 @@ async def slow_resource(): 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(): From a911c2da9bf96b6a5a95619a348056dabb3a870b Mon Sep 17 00:00:00 2001 From: Aishwarya Date: Sun, 11 May 2025 14:28:47 +0545 Subject: [PATCH 4/5] lint fix --- tests/issues/test_188_concurrency.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/issues/test_188_concurrency.py b/tests/issues/test_188_concurrency.py index 7fc18aa102..159658a34b 100644 --- a/tests/issues/test_188_concurrency.py +++ b/tests/issues/test_188_concurrency.py @@ -41,7 +41,7 @@ async def slow_resource(): tg.start_soon(client_session.call_tool, "sleep") tg.start_soon(client_session.read_resource, AnyUrl(_resource_name)) - # Verify concurrent execution by checking for overlapping calls + # 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]): From 7f1622df6840b48645db59d3ca1def912e965b2d Mon Sep 17 00:00:00 2001 From: Aishwarya Date: Sun, 11 May 2025 14:33:15 +0545 Subject: [PATCH 5/5] remove unsed variable --- tests/issues/test_188_concurrency.py | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/issues/test_188_concurrency.py b/tests/issues/test_188_concurrency.py index 159658a34b..10c462aaa2 100644 --- a/tests/issues/test_188_concurrency.py +++ b/tests/issues/test_188_concurrency.py @@ -35,7 +35,6 @@ async def slow_resource(): 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")