perf: gate deadline reminder polling (Closes #717)
This commit is contained in:
1 parent
fc79e4523d
commit
8f0df3d393
4 files changed
+98
-3
No files matched your search
@@ -87,6 +87,67 @@ async def test_deadline_reminder_fails_closed_for_incomplete_snapshot_and_before
|
||||
assert sent == []
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_deadline_reminder_skips_snapshot_until_a_device_reaches_its_local_hour(tmp_path):
|
||||
store = PushSubscriptionStore(tmp_path / "push.sqlite3")
|
||||
store.upsert("device-a", {
|
||||
"endpoint": "https://push.example/device-a",
|
||||
"keys": {"p256dh": "public-key", "auth": "auth-secret"},
|
||||
})
|
||||
store.set_deadline_preferences(
|
||||
"device-a", enabled=True, timezone="America/Los_Angeles", reminder_hour=9
|
||||
)
|
||||
snapshot_calls = 0
|
||||
|
||||
async def assigned():
|
||||
nonlocal snapshot_calls
|
||||
snapshot_calls += 1
|
||||
return {"complete": True, "items": []}
|
||||
|
||||
delivered = await dispatch_deadline_reminders(
|
||||
store,
|
||||
PushConfiguration("public", "private", "mailto:ops@example.com"),
|
||||
assigned,
|
||||
now=datetime(2026, 8, 13, 15, 0, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
assert delivered == 0
|
||||
assert snapshot_calls == 0
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_deadline_reminder_skips_snapshot_after_every_device_was_delivered_today(tmp_path):
|
||||
store = PushSubscriptionStore(tmp_path / "push.sqlite3")
|
||||
for session_id, timezone_name in (
|
||||
("device-a", "UTC"),
|
||||
("device-b", "America/New_York"),
|
||||
):
|
||||
store.upsert(session_id, {
|
||||
"endpoint": f"https://push.example/{session_id}",
|
||||
"keys": {"p256dh": "public-key", "auth": "auth-secret"},
|
||||
})
|
||||
store.set_deadline_preferences(
|
||||
session_id, enabled=True, timezone=timezone_name, reminder_hour=9
|
||||
)
|
||||
store.mark_deadline_reminder_delivered(session_id, "2026-08-13")
|
||||
snapshot_calls = 0
|
||||
|
||||
async def assigned():
|
||||
nonlocal snapshot_calls
|
||||
snapshot_calls += 1
|
||||
return {"complete": True, "items": []}
|
||||
|
||||
delivered = await dispatch_deadline_reminders(
|
||||
store,
|
||||
PushConfiguration("public", "private", "mailto:ops@example.com"),
|
||||
assigned,
|
||||
now=datetime(2026, 8, 13, 15, 0, tzinfo=timezone.utc),
|
||||
)
|
||||
|
||||
assert delivered == 0
|
||||
assert snapshot_calls == 0
|
||||
|
||||
|
||||
def test_deadline_preferences_persist_on_the_existing_device_subscription(tmp_path):
|
||||
store = PushSubscriptionStore(tmp_path / "push.sqlite3")
|
||||
store.upsert("device-a", {
|
||||
|
||||
@@ -295,6 +295,22 @@ async def test_push_poll_deadlines_continue_while_unread_dispatch_is_blocked(mon
|
||||
await poll
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_push_poll_uses_a_lower_independent_deadline_cadence(monkeypatch):
|
||||
intervals = []
|
||||
|
||||
async def capture_channel(_dispatch, *, interval):
|
||||
intervals.append(interval)
|
||||
|
||||
monkeypatch.setenv("STACKCHAIN_PUSH_POLL_SECONDS", "30")
|
||||
monkeypatch.setenv("STACKCHAIN_DEADLINE_POLL_SECONDS", "600")
|
||||
monkeypatch.setattr(main, "_push_channel_loop", capture_channel)
|
||||
|
||||
await main._push_poll_loop()
|
||||
|
||||
assert sorted(intervals) == [30.0, 600.0]
|
||||
|
||||
|
||||
@pytest.mark.anyio
|
||||
async def test_push_channel_loop_skips_missed_ticks_without_overlapping(monkeypatch):
|
||||
starts = []
|
||||
|
||||
Reference in new issue
Block a user