From 174fd8ac7eca26aff842b0746c6a3181a5affb04 Mon Sep 17 00:00:00 2001 From: Alexsander Hamir Date: Mon, 26 Jan 2026 10:50:35 -0800 Subject: [PATCH] Fix test_mcp_server_manager_config_integration_with_database cancellation error Mock _create_mcp_client to avoid network calls in health checks. This prevents asyncio.CancelledError when the test teardown closes the event loop while health checks are still pending. The test focuses on conversion logic (access_groups, description) not health check functionality, so mocking the network call is appropriate. --- tests/mcp_tests/test_mcp_server.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/tests/mcp_tests/test_mcp_server.py b/tests/mcp_tests/test_mcp_server.py index e8a1231c6fb..f56e8321b54 100644 --- a/tests/mcp_tests/test_mcp_server.py +++ b/tests/mcp_tests/test_mcp_server.py @@ -1105,9 +1105,16 @@ async def mock_get_allowed_servers(user_auth=None): test_manager.get_allowed_mcp_servers = mock_get_allowed_servers - # Test the method (this tests our second fix) - import asyncio + # Mock _create_mcp_client to return a client that completes immediately + # This avoids network calls while preserving the actual conversion logic + def mock_create_mcp_client(*args, **kwargs): + mock_client = MagicMock() + mock_client.run_with_session = AsyncMock(return_value="ok") + return mock_client + + test_manager._create_mcp_client = mock_create_mcp_client + # Test the method (this tests our second fix) servers_list = await test_manager.get_all_mcp_servers_with_health_and_teams( user_api_key_auth=mock_user_auth )