fix(memory): add thread-safe singleton initialization
- Add threading.Lock with double-check locking to ScopeManager - Add asyncio.Lock with double-check locking to MemoryReflection - Make reset_memory_metrics async with proper locking - Update test fixtures to handle async reset functions 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude Opus 4.5 <noreply@anthropic.com>
This commit is contained in:
@@ -21,9 +21,9 @@ def metrics() -> MemoryMetrics:
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_singleton() -> None:
|
||||
async def reset_singleton() -> None:
|
||||
"""Reset singleton before each test."""
|
||||
reset_memory_metrics()
|
||||
await reset_memory_metrics()
|
||||
|
||||
|
||||
class TestMemoryMetrics:
|
||||
@@ -333,7 +333,7 @@ class TestSingleton:
|
||||
metrics1 = await get_memory_metrics()
|
||||
await metrics1.inc_operations("get", "working", None, True)
|
||||
|
||||
reset_memory_metrics()
|
||||
await reset_memory_metrics()
|
||||
|
||||
metrics2 = await get_memory_metrics()
|
||||
summary = await metrics2.get_summary()
|
||||
|
||||
@@ -59,9 +59,9 @@ def create_mock_episode(
|
||||
|
||||
|
||||
@pytest.fixture(autouse=True)
|
||||
def reset_singleton() -> None:
|
||||
async def reset_singleton() -> None:
|
||||
"""Reset singleton before each test."""
|
||||
reset_memory_reflection()
|
||||
await reset_memory_reflection()
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
@@ -757,7 +757,7 @@ class TestSingleton:
|
||||
) -> None:
|
||||
"""Should create new instance after reset."""
|
||||
r1 = await get_memory_reflection(mock_session)
|
||||
reset_memory_reflection()
|
||||
await reset_memory_reflection()
|
||||
r2 = await get_memory_reflection(mock_session)
|
||||
|
||||
assert r1 is not r2
|
||||
|
||||
Reference in New Issue
Block a user