From 6d359e0681d002df032a491b5cea60a53928f955 Mon Sep 17 00:00:00 2001 From: teknium1 <127238744+teknium1@users.noreply.github.com> Date: Sun, 5 Jul 2026 15:59:39 -0700 Subject: [PATCH] =?UTF-8?q?test(mcp):=20initial-connect=20exhaustion=20now?= =?UTF-8?q?=20parks=20=E2=80=94=20update=20awaiting=20tests?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 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. --- tests/tools/test_mcp_stability.py | 9 +++++++-- tests/tools/test_mcp_tool.py | 17 ++++++++++++----- 2 files changed, 19 insertions(+), 7 deletions(-) diff --git a/tests/tools/test_mcp_stability.py b/tests/tools/test_mcp_stability.py index 494ebbbe024..796dbed913d 100644 --- a/tests/tools/test_mcp_stability.py +++ b/tests/tools/test_mcp_stability.py @@ -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()) diff --git a/tests/tools/test_mcp_tool.py b/tests/tools/test_mcp_tool.py index 6264b507a86..eeeeef7e48c 100644 --- a/tests/tools/test_mcp_tool.py +++ b/tests/tools/test_mcp_tool.py @@ -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())