fix: expire schedule and attendee caches after one hour
This commit is contained in:
1 parent
dd5a6ef5ae
commit
cd7924d890
5 files changed
+61
-13
No files matched your search
@@ -44,6 +44,42 @@ def test_payload_overwrite_updates_in_place(conn):
|
||||
assert conn.execute("SELECT COUNT(*) FROM payloads").fetchone()[0] == 1
|
||||
|
||||
|
||||
@pytest.mark.parametrize("key", ["schedule:2026-07-20", "attendees:123"])
|
||||
@pytest.mark.parametrize("age, fresh", [(3599, True), (3600, False), (7200, False), (-1, False)])
|
||||
def test_dynamic_payload_one_hour_ttl(conn, monkeypatch, key, age, fresh):
|
||||
now = _dt.datetime.combine(_dt.date.today(), _dt.time(12))
|
||||
|
||||
class Clock(_dt.datetime):
|
||||
@classmethod
|
||||
def now(cls, tz=None):
|
||||
return now
|
||||
|
||||
monkeypatch.setattr(store._dt, "datetime", Clock)
|
||||
store.put_payload(conn, key, {"status": "Reserved"})
|
||||
stamp = (now - _dt.timedelta(seconds=age)).isoformat()
|
||||
conn.execute("UPDATE payloads SET fetched_at = ? WHERE key = ?", (stamp, key))
|
||||
conn.commit()
|
||||
assert (store.get_payload(conn, key) is not None) is fresh
|
||||
|
||||
|
||||
def test_workout_keeps_same_day_cache(conn):
|
||||
key = "workout:2026-07-20:133059"
|
||||
store.put_payload(conn, key, {"name": "Example WOD"})
|
||||
stamp = _dt.datetime.combine(_dt.date.today(), _dt.time.min).isoformat()
|
||||
conn.execute("UPDATE payloads SET fetched_at = ? WHERE key = ?", (stamp, key))
|
||||
conn.commit()
|
||||
hit = store.get_payload(conn, key)
|
||||
assert hit is not None
|
||||
assert hit[0] == {"name": "Example WOD"}
|
||||
|
||||
|
||||
def test_dynamic_payload_invalid_timestamp_is_a_miss(conn):
|
||||
store.put_payload(conn, "schedule:2026-07-20", {})
|
||||
conn.execute("UPDATE payloads SET fetched_at = 'invalid'")
|
||||
conn.commit()
|
||||
assert store.get_payload(conn, "schedule:2026-07-20") is None
|
||||
|
||||
|
||||
ROWS = [
|
||||
{"class_id": "190917816", "name": "CrossFit: 5:30 PM", "start": "17:30:00",
|
||||
"end": "18:30:00", "program_id": "133059", "coach": "Pat Doyle",
|
||||
|
||||
Reference in new issue
Block a user