Split last_upsert (persisted write) and last_refresh (run liveness) in stats

This commit is contained in:
Jan Doubravský
2026-06-09 08:48:29 +02:00
parent 6dc85e4f3c
commit 8744f458cc
10 changed files with 108 additions and 11 deletions
+28
View File
@@ -202,6 +202,34 @@ def test_delta_success_resets_failure_streak(env):
assert env.cache.get_errors()["products"].consecutive == 0
# ---------------------------------------------------------------------------
# last_upsert (persisted write) vs last_refresh (in-memory run/liveness)
# ---------------------------------------------------------------------------
def _persisted_last_upsert(cache, table):
row = cache.connection.execute(
"SELECT last_refresh_at FROM _sqlmem_tables WHERE table_name = ?", (table,)
).fetchone()
return row[0] if row else None
def test_empty_delta_records_run_but_not_write(env):
"""An empty delta cycle bumps last_refresh (liveness) but not the persisted
last_upsert (write time)."""
before = _persisted_last_upsert(env.cache, "products")
# Push the watermark past every source row so the next cycle returns 0 rows.
env.cache.set_last_synced_at("products", "2099-01-01 00:00:00")
env.refresher.refresh(env.source)
# No rows written → persisted write time unchanged.
assert _persisted_last_upsert(env.cache, "products") == before
# But the cycle ran → in-memory run time recorded (and at/after the last write).
runs = env.cache.get_last_runs()
assert runs["products"] is not None
assert runs["products"] >= before
# ---------------------------------------------------------------------------
# Engine-level: PK auto-discovery, reset, end-to-end refresh
# ---------------------------------------------------------------------------