fix: address unit-of-work verify findings
Abort the transport when a bounded close ends, so a frozen server leaves no sessions over the pool once the ping has no transaction. Under the shared request deadline a block sets no timer of its own, so a single cancel closes the connection and the log has one record. Add a test that concurrent worker deliveries get separate units of work, and state the cost of the pattern against both baselines in the report. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -59,13 +59,34 @@ from sqlalchemy.ext.asyncio import ( # noqa: E402
|
||||
)
|
||||
|
||||
from src.config import settings # noqa: E402
|
||||
from src.infra.db import create_engine, create_session_factory # noqa: E402
|
||||
from src.infra.db import ( # noqa: E402
|
||||
create_engine,
|
||||
create_session_factory,
|
||||
scope,
|
||||
)
|
||||
from src.infra.db.models.base import Base # noqa: E402
|
||||
from src.infra.db.uow import SqlAlchemyUnitOfWork # noqa: E402
|
||||
|
||||
_created = False
|
||||
|
||||
|
||||
class DatabaseWarnings:
|
||||
"""Записи логгера `database`: сколько раз назван отказ."""
|
||||
|
||||
def __init__(self) -> None:
|
||||
self.events: list[str] = []
|
||||
|
||||
def warning(self, event_name: str, **_: object) -> None:
|
||||
self.events.append(event_name)
|
||||
|
||||
|
||||
@pytest.fixture
|
||||
def warnings(monkeypatch: pytest.MonkeyPatch) -> DatabaseWarnings:
|
||||
recorder = DatabaseWarnings()
|
||||
monkeypatch.setattr(scope, "logger", recorder)
|
||||
return recorder
|
||||
|
||||
|
||||
async def _admin_connection(database: str = "postgres") -> asyncpg.Connection:
|
||||
source = settings.database
|
||||
return await asyncpg.connect(
|
||||
|
||||
Reference in New Issue
Block a user