|
| 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