From 415b854045538b7e2346428bc7f1cbd2f1d9629c Mon Sep 17 00:00:00 2001 From: Trayan Azarov Date: Wed, 17 Apr 2024 13:59:45 +0300 Subject: [PATCH] test: Invariant is now applied only to persisted local segment --- chromadb/test/property/invariants.py | 12 +++++++++++- chromadb/test/test_multithreaded.py | 4 +++- 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/chromadb/test/property/invariants.py b/chromadb/test/property/invariants.py index c731b4c3049d..a7bd2c6cade4 100644 --- a/chromadb/test/property/invariants.py +++ b/chromadb/test/property/invariants.py @@ -1,5 +1,6 @@ import gc import math +from time import sleep import psutil @@ -174,8 +175,17 @@ def fd_not_exceeding_threadpool_size(threadpool_size: int) -> None: """ current_process = psutil.Process() open_files = current_process.open_files() - if len([p.path for p in open_files if "sqlite3" in p.path]) - 1 <= threadpool_size: + max_retries = 5 + retry_count = 0 + # we probably don't need the below but we keep it to avoid flaky tests. + while ( + len([p.path for p in open_files if "sqlite3" in p.path]) - 1 > threadpool_size + and retry_count < max_retries + ): gc.collect() # GC to collect the orphaned TLS objects + open_files = current_process.open_files() + retry_count += 1 + sleep(1) assert ( len([p.path for p in open_files if "sqlite3" in p.path]) - 1 <= threadpool_size ) diff --git a/chromadb/test/test_multithreaded.py b/chromadb/test/test_multithreaded.py index 8673809f62a2..a2d6f2e1ba5d 100644 --- a/chromadb/test/test_multithreaded.py +++ b/chromadb/test/test_multithreaded.py @@ -194,7 +194,9 @@ def perform_operation( exception = future.exception() if exception is not None: raise exception - if isinstance(api, SegmentAPI): # we can't check invariants for FastAPI + if ( + isinstance(api, SegmentAPI) and api.get_settings().is_persistent is True + ): # we can't check invariants for FastAPI invariants.fd_not_exceeding_threadpool_size(num_workers) # Check that invariants hold invariants.count(coll, records_set)