refactor(fc2c-i): single shared async engine with lifecycle dispose

This commit is contained in:
2026-05-15 13:53:42 -04:00
parent 0a4eb0bdc0
commit fc33c23dd5
3 changed files with 82 additions and 8 deletions
+31
View File
@@ -0,0 +1,31 @@
"""Unit: the shared engine is a memoized singleton; dispose resets it.
create_async_engine does NOT open a connection, so identity checks need no
DB and run in CI (not integration-marked).
"""
import pytest
from backend.app import extensions
@pytest.mark.asyncio
async def test_get_engine_is_singleton():
a = extensions.get_engine()
b = extensions.get_engine()
assert a is b
await extensions.dispose_engine()
@pytest.mark.asyncio
async def test_dispose_engine_allows_fresh_engine():
first = extensions.get_engine()
await extensions.dispose_engine()
second = extensions.get_engine()
assert first is not second
await extensions.dispose_engine()
def test_get_session_returns_async_context_manager():
cm = extensions.get_session()
assert hasattr(cm, "__aenter__") and hasattr(cm, "__aexit__")