|
|
3 недель назад | |
|---|---|---|
| .. | ||
| README_WORKSPACE_ISOLATION_TESTS.md | 3 недель назад | |
| __init__.py | 3 недель назад | |
| test_workspace_isolation.py | 3 недель назад | |
| test_workspace_migration_isolation.py | 3 недель назад | |
| test_workspace_sanitization.py | 3 недель назад | |
Comprehensive test coverage for LightRAG's workspace isolation feature, ensuring that different workspaces (projects) can coexist independently without data contamination or resource conflicts.
Tests: 1, 4, 8, 9, 10 Purpose: Verify that data in one workspace doesn't leak into another
Tests: 2, 5, 6 Purpose: Validate that locking mechanisms allow parallelism across workspaces while enforcing serialization within workspaces
Test: 3 Purpose: Ensure legacy code without workspace parameters still functions correctly
Test: 7 Purpose: Validate guardrails for invalid configurations
Test: 11 Purpose: Validate complete LightRAG workflows maintain isolation
# Run all workspace isolation tests
pytest tests/workspace/test_workspace_isolation.py -v
# Run specific test
pytest tests/workspace/test_workspace_isolation.py::test_lock_mechanism -v
# Run with detailed output
pytest tests/workspace/test_workspace_isolation.py -v -s
Enable stress testing with configurable number of workers:
# Enable stress mode with default 3 workers
LIGHTRAG_STRESS_TEST=true pytest tests/workspace/test_workspace_isolation.py -v
# Custom number of workers (e.g., 10)
LIGHTRAG_STRESS_TEST=true LIGHTRAG_TEST_WORKERS=10 pytest tests/workspace/test_workspace_isolation.py -v
Preserve temporary directories for manual inspection:
# Keep test artifacts (useful for debugging)
LIGHTRAG_KEEP_ARTIFACTS=true pytest tests/workspace/test_workspace_isolation.py -v
# Stress test with 20 workers and keep artifacts
LIGHTRAG_STRESS_TEST=true \
LIGHTRAG_TEST_WORKERS=20 \
LIGHTRAG_KEEP_ARTIFACTS=true \
pytest tests/workspace/test_workspace_isolation.py::test_lock_mechanism -v -s
# Recommended CI/CD command (no artifacts, default workers)
pytest tests/workspace/test_workspace_isolation.py -v --tb=short
_measure_lock_parallelismMeasures actual concurrency rather than wall-clock time.
Returns:
max_parallel: Peak number of concurrent lock holderstimeline: Ordered list of (task_name, event) tuplesmetrics: Dict with performance data (duration, concurrency, workers)Example:
workload = [
("task1", "workspace1", "namespace"),
("task2", "workspace2", "namespace"),
]
max_parallel, timeline, metrics = await _measure_lock_parallelism(workload)
# Assert on actual behavior, not timing
assert max_parallel >= 2 # Two different workspaces should run concurrently
_assert_no_timeline_overlapValidates sequential execution using finite state machine.
Validates:
Example:
timeline = [
("task1", "start"),
("task1", "end"),
("task2", "start"),
("task2", "end"),
]
_assert_no_timeline_overlap(timeline) # Passes - no overlap
timeline_bad = [
("task1", "start"),
("task2", "start"), # ERROR: task2 started before task1 ended
("task1", "end"),
]
_assert_no_timeline_overlap(timeline_bad) # Raises AssertionError
| Variable | Type | Default | Description |
|---|---|---|---|
LIGHTRAG_STRESS_TEST |
bool | false |
Enable stress testing mode |
LIGHTRAG_TEST_WORKERS |
int | 3 |
Number of parallel workers in stress mode |
LIGHTRAG_KEEP_ARTIFACTS |
bool | false |
Keep temporary test directories |
With LIGHTRAG_TEST_WORKERS=10:
Symptom: Tests pass locally but fail in CI/CD
Cause: System under heavy load, timing-based assertions
Solution: Our tests use concurrency-based assertions, not timing. If failures persist, check the timeline output in error messages.
Symptom: "Directory not empty" or "Cannot remove directory"
Cause: Concurrent test execution or OS file locking
Solution: Run tests serially (pytest -n 1) or use LIGHTRAG_KEEP_ARTIFACTS=true to inspect state
Symptom: "Lock acquisition timeout" Cause: Deadlock or resource starvation Solution: Check test output for deadlock patterns, review lock acquisition order
Enable verbose output:
pytest tests/workspace/test_workspace_isolation.py -v -s
Run single test with artifacts:
LIGHTRAG_KEEP_ARTIFACTS=true pytest tests/workspace/test_workspace_isolation.py::test_json_kv_storage_workspace_isolation -v -s
Check performance metrics: Look for the "Performance:" lines in test output showing duration and concurrency.
Inspect timeline on failure: Timeline data is included in assertion error messages.
test_<feature>_<aspect>_measure_lock_parallelism, _assert_no_timeline_overlap@pytest.mark.asyncio
async def test_new_feature():
"""
Brief description of what this test validates.
"""
# Purpose: Why this test exists
# Scope: What functions/classes this tests
print("\n" + "=" * 60)
print("TEST N: Feature Name")
print("=" * 60)
# Test implementation
# ...
print("✅ PASSED: Feature Name")
print(f" Validation details")
| Component | Data Isolation | Lock Mechanism | Backward Compat | Error Handling | E2E |
|---|---|---|---|---|---|
| shared_storage | ✅ T1, T4 | ✅ T2, T5, T6 | ✅ T3 | ✅ T7 | ✅ T11 |
| update_flags | ✅ T8 | - | - | - | - |
| JsonKVStorage | ✅ T10 | - | - | - | ✅ T11 |
| LightRAG Core | - | - | - | - | ✅ T11 |
| Namespace | ✅ T9 | - | ✅ T3 | ✅ T7 | - |
Legend: T# = Test number