Skip to content
Merged

#552 #707

Changes from 14 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
50 changes: 50 additions & 0 deletions tests/issues/test_552_windows_hang.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
import asyncio
import sys

import pytest

from mcp import ClientSession, StdioServerParameters
from mcp.client.stdio import stdio_client

# @pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test")
@pytest.mark.skipif(sys.version_info < (3, 11), reason="asyncio.timeout in 3.11+")
@pytest.mark.parametrize(
"args",
[
["/C", "echo", '{"jsonrpc": "2.0", "id": 1, "result": null}'],
["dfghfgh"],
["/C", "echo"],
],
)
@pytest.mark.anyio
async def test_windows_process_creation(args):
"""
Test that directly tests the process creation function that was fixed in issue #552.
This simpler test verifies that Windows process creation works without hanging.
"""
# Use a simple command that should complete quickly on Windows
params = StdioServerParameters(
command="cmd",
# Echo a valid JSON-RPC response message that will be parsed correctly
args=args,
)

# Directly test the fixed function that was causing the hanging issue
try:
# Set a timeout to prevent hanging
async with asyncio.timeout(5):
# Test the actual process creation function that was fixed
async with stdio_client(params) as (read, write):
print("inside client")
async with ClientSession(read, write) as c:
print("inside ClientSession")
await c.initialize()

except asyncio.TimeoutError:
pytest.xfail("Process creation timed out, indicating a hang issue")
except ProcessLookupError:
pytest.xfail("Process creation failed with ProcessLookupError")
except Exception as e:
assert "ExceptionGroup" in repr(e), f"Unexpected error: {e}"
assert "ProcessLookupError" in repr(e), f"Unexpected error: {e}"
pytest.xfail(f"Expected error: {e}")
Loading