From fd637e0f1e088b7fa33243c08a256920c570cac6 Mon Sep 17 00:00:00 2001 From: stroblme Date: Mon, 2 Nov 2026 19:14:59 +0100 Subject: [PATCH] Tests clear flow tombstones between modules with the other engine rows, and the tombstone test commits its prune before checking the count, so a wrong count no longer holds the write lock over the tests after it --- backend/tests/conftest.py | 5 ++++- backend/tests/test_tombstones.py | 8 ++++++-- 2 files changed, 10 insertions(+), 3 deletions(-) diff --git a/backend/tests/conftest.py b/backend/tests/conftest.py index a6af140..ef3f4d7 100644 --- a/backend/tests/conftest.py +++ b/backend/tests/conftest.py @@ -18,6 +18,7 @@ from fluksio.main import app from fluksio.models import ( EngineEvent, FlowRun, + FlowTombstone, MetricBucket, Run, RunArtifact, @@ -69,7 +70,8 @@ def db() -> Generator[Session, None, None]: #: Tables the engine writes to on its own, from the collector and the run -#: service the module-scoped app starts. +#: service the module-scoped app starts, and the tombstones a flow deleted +#: through it leaves for that history. _ENGINE_TABLES = ( RunArtifact, RunMetric, @@ -78,6 +80,7 @@ _ENGINE_TABLES = ( FlowRun, EngineEvent, MetricBucket, + FlowTombstone, ) diff --git a/backend/tests/test_tombstones.py b/backend/tests/test_tombstones.py index f9fd284..545a00a 100644 --- a/backend/tests/test_tombstones.py +++ b/backend/tests/test_tombstones.py @@ -36,8 +36,11 @@ def test_a_tombstone_stays_while_history_names_its_id(db: Session) -> None: assert graves.recorded("wren_train") == "wren_train" # history, no tombstone assert graves.recorded("f_nothing") is None - assert tombstones.prune(db) == 1 + # Committed before it is checked, so a wrong count does not leave this + # session holding the write lock for every test after it. + pruned = tombstones.prune(db) db.commit() + assert pruned == 1 kept = {stone.id for stone in db.exec(select(FlowTombstone))} assert kept == {"f_gonegone", "f_trainee", "f_measured"} @@ -45,8 +48,9 @@ def test_a_tombstone_stays_while_history_names_its_id(db: Session) -> None: db.exec(delete(MetricBucket)) # type: ignore[call-overload] db.exec(delete(EngineEvent)) # type: ignore[call-overload] db.commit() - assert tombstones.prune(db) == 3 + pruned = tombstones.prune(db) db.commit() + assert pruned == 3 def test_a_name_comes_from_the_live_flow_then_its_tombstone_then_the_id(