test(docker): #5152's tests read rows with SQL and the clock they render against

- The status test imported the plugin's models after the app had mapped
  them ("already defined"); it reads docker_host_status with SQL.
- The swarm-expiry count awaited inside a generator expression.
- The page test's since came from the module's NOW, so |ago said "5m 4s";
  it is built at test time and the assertion checks the minutes.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-10-06 18:45:57 -04:00
co-authored by Claude Opus 5.5
parent bcd0563f39
commit d8bacc7149
2 changed files with 19 additions and 10 deletions
+15 -7
View File
@@ -422,6 +422,7 @@ def test_an_empty_snapshot_from_a_docker_that_answered_clears_the_host(app):
@_NEEDS_DB
def test_docker_status_is_recorded_once_a_host_has_had_docker(app):
from sqlalchemy import text
from steward.models.hosts import Host
persist = _persist_fn(app)
@@ -430,7 +431,6 @@ def test_docker_status_is_recorded_once_a_host_has_had_docker(app):
t3 = t1 + timedelta(seconds=60)
async def _go():
from plugins.docker.models import DockerHostStatus
seen = []
async with app.db_sessionmaker() as s:
async with s.begin():
@@ -440,14 +440,20 @@ def test_docker_status_is_recorded_once_a_host_has_had_docker(app):
await s.flush()
gone = {"status": "unavailable", "detail": "no Docker socket at /var/run/docker.sock"}
await persist(s, never, [], status=dict(gone, at=t1))
seen.append(await s.get(DockerHostStatus, never.id))
await s.flush()
async def row(host):
return (await s.execute(text(
"SELECT status, detail, since, reported_at FROM docker_host_status "
"WHERE host_id = :h"), {"h": host.id})).first()
seen.append(await row(never))
for status, at in (({"status": "ok", "detail": None}, t1),
(gone, t2), (gone, t3),
({"status": "error", "detail": "permission denied on /var/run/docker.sock"}, t3)):
await persist(s, had, [], status=dict(status, at=at))
await s.flush()
row = await s.get(DockerHostStatus, had.id)
seen.append((row.status, row.detail, row.since, row.reported_at))
seen.append(tuple(await row(had)))
return seen
never, ok, gone1, gone2, err = asyncio.run(_go())
@@ -476,9 +482,11 @@ def test_a_node_that_is_no_longer_a_manager_loses_its_swarm_rows(app):
await s.flush()
async def counts():
return tuple((await s.execute(text(
f"SELECT count(*) FROM {t} WHERE host_id = :h"), {"h": h.id})).scalar()
for t in ("docker_swarm_services", "docker_swarm_nodes"))
out = []
for t in ("docker_swarm_services", "docker_swarm_nodes"):
out.append((await s.execute(text(
f"SELECT count(*) FROM {t} WHERE host_id = :h"), {"h": h.id})).scalar())
return tuple(out)
await persist(s, h, [], swarm, status={"status": "ok", "detail": None, "at": t1})
manager = await counts()