fix(agent99): bound DB sessions and expire stale outcomes
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 1s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 4m0s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
AWOOOI Harbor 110 Local Repair / workflow-shape (push) Successful in 1s
AWOOOI Harbor 110 Local Repair / harbor-110-local-repair (push) Successful in 17s
Some checks failed
CD Pipeline / workflow-shape (push) Successful in 1s
CD Pipeline / cancel-stale-cd (push) Has been skipped
CD Pipeline / tests (push) Successful in 4m0s
CD Pipeline / post-deploy-checks (push) Has been cancelled
CD Pipeline / build-and-deploy (push) Has been cancelled
AWOOOI Harbor 110 Local Repair / workflow-shape (push) Successful in 1s
AWOOOI Harbor 110 Local Repair / harbor-110-local-repair (push) Successful in 17s
This commit is contained in:
@@ -8,6 +8,7 @@ Runtime bootstrap guard tests.
|
||||
|
||||
from __future__ import annotations
|
||||
|
||||
import asyncio
|
||||
import inspect
|
||||
from collections.abc import Awaitable
|
||||
from pathlib import Path
|
||||
@@ -223,6 +224,52 @@ def test_get_engine_uses_null_pool_for_bounded_background_processes(monkeypatch)
|
||||
assert "pool_timeout" not in captured
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_null_pool_session_limiter_serializes_worker_db_sessions(
|
||||
monkeypatch,
|
||||
) -> None:
|
||||
from src.db import base as db_base
|
||||
|
||||
assert "async with _database_session_slot()" in inspect.getsource(
|
||||
db_base.get_db
|
||||
)
|
||||
assert "async with _database_session_slot()" in inspect.getsource(
|
||||
db_base.get_db_context
|
||||
)
|
||||
monkeypatch.setattr(db_base.settings, "DATABASE_NULL_POOL", True)
|
||||
monkeypatch.setattr(
|
||||
db_base.settings,
|
||||
"DATABASE_NULL_POOL_CONCURRENCY_LIMIT",
|
||||
1,
|
||||
)
|
||||
monkeypatch.setattr(db_base.settings, "DATABASE_POOL_TIMEOUT_SECONDS", 1.0)
|
||||
monkeypatch.setattr(db_base, "_null_pool_session_limiter", None)
|
||||
monkeypatch.setattr(db_base, "_null_pool_session_limiter_size", 0)
|
||||
first_entered = asyncio.Event()
|
||||
release_first = asyncio.Event()
|
||||
second_entered = asyncio.Event()
|
||||
|
||||
async def first_session() -> None:
|
||||
async with db_base._database_session_slot():
|
||||
first_entered.set()
|
||||
await release_first.wait()
|
||||
|
||||
async def second_session() -> None:
|
||||
async with db_base._database_session_slot():
|
||||
second_entered.set()
|
||||
|
||||
first_task = asyncio.create_task(first_session())
|
||||
await first_entered.wait()
|
||||
second_task = asyncio.create_task(second_session())
|
||||
await asyncio.sleep(0)
|
||||
|
||||
assert second_entered.is_set() is False
|
||||
|
||||
release_first.set()
|
||||
await asyncio.gather(first_task, second_task)
|
||||
assert second_entered.is_set() is True
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_init_db_serializes_bootstrap_ddl_with_advisory_lock(monkeypatch):
|
||||
from src.db import base as db_base
|
||||
|
||||
Reference in New Issue
Block a user