fix(agents): bound runtime receipt consumer overlay
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 2m43s
CD Pipeline / build-and-deploy (push) Successful in 5m40s
CD Pipeline / post-deploy-checks (push) Has been cancelled
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 2m43s
CD Pipeline / build-and-deploy (push) Successful in 5m40s
CD Pipeline / post-deploy-checks (push) Has been cancelled
This commit is contained in:
@@ -44,6 +44,7 @@ class _FakeMappingResult:
|
||||
class _BudgetRuntimeDb:
|
||||
def __init__(self):
|
||||
self.statements: list[str] = []
|
||||
self.expire_budget_after_operation_counts = None
|
||||
|
||||
async def execute(self, statement, *_args, **_kwargs):
|
||||
sql = str(statement)
|
||||
@@ -51,6 +52,8 @@ class _BudgetRuntimeDb:
|
||||
if "SET LOCAL statement_timeout" in sql:
|
||||
return _FakeMappingResult([])
|
||||
if "FROM automation_operation_log" in sql and "GROUP BY 1, status" in sql:
|
||||
if self.expire_budget_after_operation_counts is not None:
|
||||
self.expire_budget_after_operation_counts()
|
||||
return _FakeMappingResult([
|
||||
{
|
||||
"operation_type": "ansible_apply_executed",
|
||||
@@ -293,9 +296,13 @@ async def test_live_runtime_receipt_readback_returns_partial_when_query_budget_e
|
||||
tick = {"value": 100.0}
|
||||
|
||||
def _fake_monotonic():
|
||||
tick["value"] += 0.05
|
||||
return tick["value"]
|
||||
|
||||
def _expire_budget():
|
||||
tick["value"] = 101.0
|
||||
|
||||
fake_db.expire_budget_after_operation_counts = _expire_budget
|
||||
|
||||
async def _fake_consumer_readback(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
return _log_controlled_writeback_consumer_readback()
|
||||
@@ -345,6 +352,37 @@ async def test_live_runtime_receipt_readback_returns_partial_when_query_budget_e
|
||||
)
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_log_controlled_writeback_consumer_timeout_returns_fallback(
|
||||
monkeypatch,
|
||||
):
|
||||
async def _slow_consumer_readback(*, project_id: str):
|
||||
assert project_id == "awoooi"
|
||||
await asyncio.sleep(1)
|
||||
return _log_controlled_writeback_consumer_readback()
|
||||
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"_LOG_CONTROLLED_WRITEBACK_CONSUMER_TIMEOUT_SECONDS",
|
||||
0.01,
|
||||
)
|
||||
monkeypatch.setattr(
|
||||
runtime_control_module,
|
||||
"load_latest_ai_agent_log_controlled_writeback_consumer_readback",
|
||||
_slow_consumer_readback,
|
||||
)
|
||||
|
||||
readback = await runtime_control_module._load_log_controlled_writeback_consumer_readback(
|
||||
project_id="awoooi",
|
||||
)
|
||||
|
||||
assert readback["status"] == "blocked_waiting_controlled_writeback_consumer_receipts"
|
||||
assert "log_controlled_writeback_consumer_readback_unavailable" in readback[
|
||||
"active_blockers"
|
||||
]
|
||||
assert readback["readback"]["error_type"] == "TimeoutError"
|
||||
|
||||
|
||||
@pytest.mark.asyncio
|
||||
async def test_live_runtime_receipt_readback_uses_short_cache_to_protect_db_pool(
|
||||
monkeypatch,
|
||||
|
||||
Reference in New Issue
Block a user