test(mcp): initial-connect exhaustion now parks — update awaiting tests

Two pre-existing tests awaited run() to return after initial-connect
retry exhaustion; with #57477's parking that await hangs (CI: 300s
SIGKILL on slices 4 and 6). Assert the new contract instead: the task
stays alive (parked) and exits on shutdown.
This commit is contained in:
teknium1 2026-07-05 15:59:39 -07:00 committed by Teknium
parent b80b0b682a
commit 6d359e0681
2 changed files with 19 additions and 7 deletions

View file

@ -560,7 +560,7 @@ class TestMCPInitialConnectionRetry:
asyncio.get_event_loop().run_until_complete(_run())
def test_initial_connect_gives_up_after_max_retries(self):
"""Server gives up after _MAX_INITIAL_CONNECT_RETRIES failures."""
"""Server parks (does not exit) after _MAX_INITIAL_CONNECT_RETRIES failures."""
from tools.mcp_tool import MCPServerTask, _MAX_INITIAL_CONNECT_RETRIES
call_count = 0
@ -583,8 +583,13 @@ class TestMCPInitialConnectionRetry:
assert "DNS resolution failed" in str(server._error)
# 1 initial + N retries = _MAX_INITIAL_CONNECT_RETRIES + 1 total attempts
assert call_count == _MAX_INITIAL_CONNECT_RETRIES + 1
# The task parks for later revival instead of exiting.
await asyncio.sleep(0)
assert not task.done(), "run task should park, not exit"
await task
server._shutdown_event.set()
server._reconnect_event.set()
await asyncio.wait_for(task, timeout=5)
asyncio.get_event_loop().run_until_complete(_run())

View file

@ -1876,12 +1876,19 @@ class TestReconnection:
with patch.object(MCPServerTask, "_run_stdio", patched_run_stdio), \
patch("asyncio.sleep", new_callable=AsyncMock):
await server.run({"command": "test"})
task = asyncio.ensure_future(server.run({"command": "test"}))
await server._ready.wait()
# Now retries up to _MAX_INITIAL_CONNECT_RETRIES before giving up
assert run_count == _MAX_INITIAL_CONNECT_RETRIES + 1
assert server._error is not None
assert "cannot connect" in str(server._error)
# Now retries up to _MAX_INITIAL_CONNECT_RETRIES, then PARKS
# (keeps the task alive for later revival) instead of exiting.
assert run_count == _MAX_INITIAL_CONNECT_RETRIES + 1
assert server._error is not None
assert "cannot connect" in str(server._error)
assert not task.done(), "run task should park, not exit"
server._shutdown_event.set()
server._reconnect_event.set()
await asyncio.wait_for(task, timeout=5)
asyncio.run(_test())