This commit provides a minimal, focused fix for CI hanging issues by addressing the root causes: **Key Changes:** 1. **ZMQ Resource Management:** - Remove `context.term()` calls that were causing hangs - Add `socket.setsockopt(zmq.LINGER, 0)` to prevent blocking on close - Keep socket operations simple with default timeouts (no artificial limits) 2. **Process Cleanup:** - Add timeout (1s) to final `process.wait()` in embedding server manager - Prevent infinite waiting that was causing CI hangs 3. **Resource Cleanup Methods:** - Add simple `cleanup()` methods to searchers and API classes - Focus on C++ object destruction for DiskANN backend - Avoid complex cleanup logic that could introduce new issues 4. **Basic Test Safety:** - Simple pytest-timeout configuration (300s) - Basic test session cleanup using psutil - Minimal conftest.py without complex logic **Philosophy:** This solution avoids the complex multi-layered fixes from the previous PR chain. Instead, it targets the specific root causes: - ZMQ context termination blocking - Process wait() without timeout - C++ resource leaks in backends 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <noreply@anthropic.com>
39 lines
1013 B
Python
39 lines
1013 B
Python
"""Pytest configuration and fixtures for LEANN tests."""
|
|
|
|
import os
|
|
import pytest
|
|
|
|
|
|
@pytest.fixture(autouse=True)
|
|
def test_environment():
|
|
"""Set up test environment variables."""
|
|
# Mark as test environment to skip memory-intensive operations
|
|
os.environ["CI"] = "true"
|
|
yield
|
|
|
|
|
|
@pytest.fixture(scope="session", autouse=True)
|
|
def cleanup_session():
|
|
"""Session-level cleanup to ensure no hanging processes."""
|
|
yield
|
|
|
|
# Basic cleanup after all tests
|
|
try:
|
|
import psutil
|
|
import os
|
|
|
|
current_process = psutil.Process(os.getpid())
|
|
children = current_process.children(recursive=True)
|
|
|
|
for child in children:
|
|
try:
|
|
child.terminate()
|
|
except psutil.NoSuchProcess:
|
|
pass
|
|
|
|
# Give them time to terminate gracefully
|
|
psutil.wait_procs(children, timeout=3)
|
|
|
|
except Exception:
|
|
# Don't fail tests due to cleanup errors
|
|
pass |