Skip to content

Commit 7a84ecb

Browse files
committed
Fix Windows hang in test by properly using stdio_client
Refactored test to utilize `stdio_client` for more accurate simulation of the fixed behavior and added handling for proper initialization with `ClientSession`. Increased timeout to 10 seconds to prevent premature failures and ensured hanging issue is properly caught and reported. Signed-off-by: DanielAvdar <66269169+DanielAvdar@users.noreply.github.com>
1 parent 289281b commit 7a84ecb

File tree

1 file changed

+17
-23
lines changed

1 file changed

+17
-23
lines changed

tests/issues/test_552_windows_hang.py

Lines changed: 17 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33

44
import pytest
55

6-
from mcp import StdioServerParameters
7-
from mcp.client.stdio import _create_platform_compatible_process
6+
from mcp import ClientSession, StdioServerParameters
7+
from mcp.client.stdio import stdio_client
88

99

1010
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test")
@@ -16,31 +16,25 @@ async def test_windows_process_creation():
1616
"""
1717
# Use a simple command that should complete quickly on Windows
1818
params = StdioServerParameters(
19-
command="cmd", args=["/c", "echo", "Test successful"]
19+
command="cmd",
20+
# Echo a valid JSON-RPC response message that will be parsed correctly
21+
args=[
22+
"/c",
23+
"echo",
24+
'{"jsonrpc":"2.0","id":1,"result":{"status":"success"}}',
25+
],
2026
)
2127

2228
# Directly test the fixed function that was causing the hanging issue
23-
process = None
2429
try:
2530
# Set a timeout to prevent hanging
26-
async with asyncio.timeout(3):
31+
async with asyncio.timeout(10):
2732
# Test the actual process creation function that was fixed
28-
process = await _create_platform_compatible_process(
29-
command=params.command, args=params.args, env=None
30-
)
33+
async with stdio_client(params) as (read, write):
34+
print("inside client")
35+
async with ClientSession(read, write) as c:
36+
print("inside ClientSession")
37+
await c.initialize()
3138

32-
# If we get here without hanging, the test is successful
33-
assert process is not None, "Process should be created successfully"
34-
35-
# Read from stdout to verify process works
36-
if process.stdout:
37-
output = await process.stdout.receive()
38-
assert output, "Process should produce output"
39-
finally:
40-
# Clean up process
41-
if process:
42-
try:
43-
process.terminate()
44-
except Exception:
45-
# Ignore errors during cleanup
46-
pass
39+
except asyncio.TimeoutError:
40+
pytest.fail("Process creation timed out, indicating a hang issue")

0 commit comments

Comments
 (0)