Files
rengine/tests/api/test_pool_capacity.py
T
Yogesh Ojha ad47eb4fb9 feat(worker): split scan stages, scan control and background jobs into three workers
Stage tasks hold a slot for their whole tool run, so step hand-overs and
finalize queued behind them and background jobs took scan slots.

- worker-scans consumes scans (run_scan_stage only), scalable with --scale
- worker-control consumes scan_control: launch, hand-over, resume, finalize
- worker-default consumes default and critical
- reaper reads both scan queues; readiness requires a consumer on every queue
- connection budget counts every worker; max_connections 250
2026-09-24 21:00:44 +05:30

38 lines
1.2 KiB
Python

from __future__ import annotations
import logging
import pytest
from app.config import settings
from app.core.database import check_capacity, pool_demand
pytestmark = pytest.mark.api
def test_demand_counts_every_pool():
per_child = settings.WORKER_DB_POOL_SIZE + settings.WORKER_DB_MAX_OVERFLOW
expected = (
settings.DB_POOL_SIZE
+ settings.DB_MAX_OVERFLOW
+ settings.CELERY_SCAN_CONCURRENCY * per_child
+ settings.CELERY_CONTROL_CONCURRENCY * per_child
+ settings.CELERY_DEFAULT_CONCURRENCY * per_child
+ per_child
)
assert pool_demand() == expected
assert pool_demand() > settings.DB_POOL_SIZE, "a worker pool is a pool too"
async def test_the_configured_pools_fit_the_configured_server(caplog):
with caplog.at_level(logging.WARNING):
await check_capacity()
assert "outgrow" not in caplog.text
async def test_it_warns_rather_than_failing_when_they_do_not(monkeypatch, caplog):
monkeypatch.setattr(settings, "DB_MAX_OVERFLOW", 10_000)
with caplog.at_level(logging.WARNING):
await check_capacity()
assert "outgrow" in caplog.text, "a silent exhaustion is a production incident"