Skip to content

Commit 9a797c2

Browse files
committed
Add Windows-specific test for process creation to prevent hanging
Signed-off-by: DanielAvdar <[email protected]>
1 parent ed25167 commit 9a797c2

File tree

1 file changed

+46
-0
lines changed

1 file changed

+46
-0
lines changed

tests/issues/test_552_windows_hang.py

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
import asyncio
2+
import sys
3+
4+
import pytest
5+
6+
from mcp import StdioServerParameters
7+
from mcp.client.stdio import _create_platform_compatible_process
8+
9+
10+
@pytest.mark.skipif(sys.platform != "win32", reason="Windows-specific test")
11+
@pytest.mark.anyio
12+
async def test_windows_process_creation():
13+
"""
14+
Test that directly tests the process creation function that was fixed in issue #552.
15+
This simpler test verifies that Windows process creation works without hanging.
16+
"""
17+
# Use a simple command that should complete quickly on Windows
18+
params = StdioServerParameters(
19+
command="cmd", args=["/c", "echo", "Test successful"]
20+
)
21+
22+
# Directly test the fixed function that was causing the hanging issue
23+
process = None
24+
try:
25+
# Set a timeout to prevent hanging
26+
async with asyncio.timeout(3):
27+
# 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+
)
31+
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

0 commit comments

Comments
 (0)