From eb71969d2cd99d5afc4dbb181311524391185f19 Mon Sep 17 00:00:00 2001 From: Andy Lee Date: Wed, 13 Aug 2025 18:48:42 -0700 Subject: [PATCH] tests: call searcher.cleanup()/chat.cleanup() to ensure background embedding servers terminate after tests --- tests/test_basic.py | 5 +++++ tests/test_readme_examples.py | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/tests/test_basic.py b/tests/test_basic.py index 800b0ac..651111f 100644 --- a/tests/test_basic.py +++ b/tests/test_basic.py @@ -64,6 +64,9 @@ def test_backend_basic(backend_name): assert isinstance(results[0], SearchResult) assert "topic 2" in results[0].text or "document" in results[0].text + # Ensure cleanup to avoid hanging background servers + searcher.cleanup() + @pytest.mark.skipif( os.environ.get("CI") == "true", reason="Skip model tests in CI to avoid MPS memory issues" @@ -90,3 +93,5 @@ def test_large_index(): searcher = LeannSearcher(index_path) results = searcher.search(["word10 word20"], top_k=10) assert len(results[0]) == 10 + # Cleanup + searcher.cleanup() diff --git a/tests/test_readme_examples.py b/tests/test_readme_examples.py index fe69e4a..818b10d 100644 --- a/tests/test_readme_examples.py +++ b/tests/test_readme_examples.py @@ -59,6 +59,9 @@ def test_readme_basic_example(backend_name): # The second text about banana-crocodile should be more relevant assert "banana" in results[0].text or "crocodile" in results[0].text + # Ensure we cleanup background embedding server + searcher.cleanup() + # Chat with your data (using simulated LLM to avoid external dependencies) chat = LeannChat(INDEX_PATH, llm_config={"type": "simulated"}) response = chat.ask("How much storage does LEANN save?", top_k=1) @@ -66,6 +69,8 @@ def test_readme_basic_example(backend_name): # Verify chat works assert isinstance(response, str) assert len(response) > 0 + # Cleanup chat resources + chat.cleanup() def test_readme_imports():