Report how long a run has been going, not just how long it took

This commit is contained in:
2026-08-25 18:33:28 +02:00
parent c3ff7df192
commit 4cdcf19de1
4 changed files with 67 additions and 3 deletions
+26 -1
View File
@@ -5,7 +5,7 @@ The pipeline half — what a hit restores and what a key is made of — is in
"""
import json
from datetime import UTC, datetime
from datetime import UTC, datetime, timedelta
import pytest
from sqlmodel import Session, col, select
@@ -286,6 +286,31 @@ def test_the_overview_counts_a_flow_the_list_page_would_not_reach(
assert (row["runs"], row["running"], row["queued"]) == (3, 1, 0)
def test_a_running_run_reports_how_long_it_has_been_going(
client, superuser_token_headers
):
"""A duration is only written at the end; until then, time since it began."""
with Session(db_engine) as session:
session.add(
Run(
id="in-flight",
flow="timed",
status="running",
created_at=datetime.now(UTC),
started_at=datetime.now(UTC) - timedelta(seconds=30),
)
)
session.commit()
rows = client.get(
f"{settings.API_V1_STR}/runs",
headers=superuser_token_headers,
params={"flow": "timed"},
).json()
assert rows[0]["duration_ms"] >= 30_000
def test_overview_is_not_read_as_a_run_id(client, superuser_token_headers):
"""`/overview` is declared before `/{run_id}`, which would swallow it."""
answer = client.get(