Skip to content

Commit 7a432fc

Browse files
committed
test(chroma0): Add unittests.
1 parent 29dda21 commit 7a432fc

File tree

2 files changed

+461
-16
lines changed

2 files changed

+461
-16
lines changed

src/vectorcode/database/chroma0.py

Lines changed: 7 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -93,7 +93,7 @@ async def _try_server(base_url: str):
9393
return False
9494

9595

96-
async def _wait_for_server(base_url: str, timeout: int = 10):
96+
async def _wait_for_server(base_url: str, timeout: int = 10): # pragma: nocover
9797
# Poll the server until it's ready or timeout is reached
9898

9999
start_time = asyncio.get_event_loop().time()
@@ -165,17 +165,10 @@ def __new__(cls) -> "_Chroma0ClientManager":
165165
cls.singleton = super().__new__(cls)
166166
cls.singleton.__clients = {}
167167

168-
atexit.register(cls.singleton._atexit)
168+
atexit.register(cls.singleton.kill_servers)
169169

170170
return cls.singleton
171171

172-
def _atexit(self):
173-
try:
174-
loop = asyncio.get_running_loop()
175-
except RuntimeError:
176-
loop = asyncio.new_event_loop()
177-
loop.run_until_complete(self.kill_servers())
178-
179172
@contextlib.asynccontextmanager
180173
async def get_client(self, configs: Config, need_lock: bool = True):
181174
project_root = str(expand_path(str(configs.project_root), True))
@@ -212,13 +205,11 @@ async def get_client(self, configs: Config, need_lock: bool = True):
212205
def get_processes(self) -> list[Process]: # pragma: nocover
213206
return [i.process for i in self.__clients.values() if i.process is not None]
214207

215-
async def kill_servers(self): # pragma: nocover
216-
termination_tasks: list[asyncio.Task] = []
208+
def kill_servers(self): # pragma: nocover
217209
for p in self.get_processes():
218-
_logger.info(f"Killing bundled chroma server with PID: {p.pid}")
219-
p.terminate()
220-
termination_tasks.append(asyncio.create_task(p.wait()))
221-
await asyncio.gather(*termination_tasks)
210+
if p.returncode is None:
211+
_logger.info(f"Killing bundled chroma server with PID: {p.pid}")
212+
p.terminate()
222213

223214
async def _create_client(self, configs: Config) -> AsyncClientAPI:
224215
settings: dict[str, Any] = {"anonymized_telemetry": False}
@@ -249,7 +240,7 @@ async def _create_client(self, configs: Config) -> AsyncClientAPI:
249240
port=int(settings_obj.chroma_server_http_port or 8000),
250241
)
251242

252-
def clear(self):
243+
def clear(self): # pragma: nocover
253244
self.__clients.clear()
254245

255246

0 commit comments

Comments
 (0)