Skip to content

Commit 7ae6ea2

Browse files
author
Zhe Yu
committed
fix(cli): Fix termination and add test case for kill_servers
1 parent 27c9a0d commit 7ae6ea2

2 files changed

Lines changed: 22 additions & 2 deletions

File tree

src/vectorcode/common.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -288,7 +288,7 @@ def get_processes(self) -> list[Process]:
288288

289289
async def kill_servers(self):
290290
termination_tasks: list[asyncio.Task] = []
291-
for p in ClientManager().get_processes():
291+
for p in self.get_processes():
292292
logger.info(f"Killing bundled chroma server with PID: {p.pid}")
293293
p.terminate()
294294
termination_tasks.append(asyncio.create_task(p.wait()))

tests/test_common.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
import subprocess
44
import sys
55
import tempfile
6-
from unittest.mock import MagicMock, patch
6+
from unittest.mock import AsyncMock, MagicMock, patch
77

88
import httpx
99
import pytest
@@ -607,3 +607,23 @@ async def test_client_manager_get_client():
607607
async with manager.get_client(Config()):
608608
mock_try_server.assert_called_once()
609609
mock_start_server.assert_not_called()
610+
611+
612+
@pytest.mark.asyncio
613+
async def test_client_manager_kill_servers():
614+
manager = ClientManager()
615+
manager.clear()
616+
617+
async def _try_server(url):
618+
return "127.0.0.1" in url or "localhost" in url
619+
620+
mock_process = AsyncMock()
621+
with (
622+
patch("vectorcode.common.start_server", return_value=mock_process),
623+
patch("vectorcode.common.try_server", side_effect=_try_server),
624+
):
625+
manager._create_client = AsyncMock(return_value=AsyncMock())
626+
async with manager.get_client(Config(db_url="http://test_host:1081")):
627+
pass
628+
await manager.kill_servers()
629+
mock_process.terminate.assert_called_once()

0 commit comments

Comments
 (0)