/ aegisvision / tests / test_analysis_scheduler.py
swadhinbiswas feat: AegisVision v2 — AI enterprise surveillance & monitoring platform · 8/8/2026
7ad9221
21 lines · 675 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
"""AnalysisScheduler: shared budget + bounded pool sanity checks."""

from app.services.analysis_scheduler import analysis_scheduler


def test_pool_runs_job():
    fut = analysis_scheduler.run(lambda: 42)
    assert fut.result(timeout=5) == 42


def test_token_bucket_drains():
    # Burning without a pause should empty the global budget and it must be
    # exhausted for a moment rather than never returning False.
    for _ in range(1000):
        analysis_scheduler.try_acquire()
    assert analysis_scheduler.try_acquire() is False


def test_available_is_bounded():
    cap = analysis_scheduler._capacity
    assert 0.0 <= analysis_scheduler.available() <= cap + 0.01