@@ -280,11 +280,13 @@ async def test_check_health_success(self, mock_health, mock_update):
280280 @patch ('backend.services.remote_mcp_service.update_mcp_status_by_name_and_url' )
281281 @patch ('backend.services.remote_mcp_service.mcp_server_health' )
282282 async def test_check_health_false (self , mock_health , mock_update ):
283- """Test health check failure"""
283+ """Test health check failure - should raise MCPConnectionError when status is False """
284284 mock_health .return_value = False
285285
286- await check_mcp_health_and_update_db ('http://srv' , 'name' , 'tid' , 'uid' )
286+ with self .assertRaises (MCPConnectionError ) as context :
287+ await check_mcp_health_and_update_db ('http://srv' , 'name' , 'tid' , 'uid' )
287288
289+ self .assertEqual (str (context .exception ), "MCP connection failed" )
288290 mock_update .assert_called_once_with (
289291 mcp_name = 'name' ,
290292 mcp_server = 'http://srv' ,
@@ -308,12 +310,14 @@ async def test_update_db_fail(self, mock_health, mock_update):
308310 @patch ('backend.services.remote_mcp_service.update_mcp_status_by_name_and_url' )
309311 @patch ('backend.services.remote_mcp_service.mcp_server_health' )
310312 async def test_health_check_exception (self , mock_health , mock_update ):
311- """Test health check exception - should catch exception and set status to False"""
313+ """Test health check exception - should catch exception, set status to False, and raise MCPConnectionError """
312314 mock_health .side_effect = MCPConnectionError ("Connection failed" )
313315
314- # Should not raise exception, but should set status to False
315- await check_mcp_health_and_update_db ('http://srv' , 'name' , 'tid' , 'uid' )
316+ # Should catch the exception from mcp_server_health, set status to False, and then raise MCPConnectionError
317+ with self .assertRaises (MCPConnectionError ) as context :
318+ await check_mcp_health_and_update_db ('http://srv' , 'name' , 'tid' , 'uid' )
316319
320+ self .assertEqual (str (context .exception ), "MCP connection failed" )
317321 mock_health .assert_called_once_with (remote_mcp_server = 'http://srv' )
318322 mock_update .assert_called_once_with (
319323 mcp_name = 'name' ,
0 commit comments