Split last_upsert (persisted write) and last_refresh (run liveness) in stats
This commit is contained in:
@@ -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
|
||||
# ---------------------------------------------------------------------------
|
||||
|
||||
@@ -96,6 +96,15 @@ def test_stats_no_error_by_default(source_engine, patched_cache):
|
||||
engine.close()
|
||||
|
||||
|
||||
def test_stats_exposes_last_upsert_and_last_refresh(source_engine, patched_cache):
|
||||
engine = CachingEngine(source_engine)
|
||||
engine.execute("SELECT id, name FROM products")
|
||||
s = engine.stats.tables["products"]
|
||||
assert s.last_upsert is not None # the load wrote rows (persisted)
|
||||
assert s.last_refresh is not None # the load also counts as a refresh-cycle run
|
||||
engine.close()
|
||||
|
||||
|
||||
# --- a table being loaded for the first time shows up as "loading" ----------
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user