feat(events): stream Redis invalidations over SSE

This commit is contained in:
2026-08-28 20:03:11 +00:00 Unverified
parent b59a038351
commit 455e4240ac
16 changed files with 453 additions and 1 deletions
+30
View File
@@ -0,0 +1,30 @@
import { afterEach, describe, expect, it, vi } from "vitest";
import { createRefreshScheduler } from "./refresh";
afterEach(() => {
vi.useRealTimers();
});
describe("authoritative refresh scheduler", () => {
it("refetches on connection and coalesces duplicate notifications", async () => {
vi.useFakeTimers();
const refresh = vi.fn();
const scheduler = createRefreshScheduler(refresh, { delayMs: 25 });
const event = { type: "page.updated" as const, id: "page", version: 5 };
scheduler.connected();
await vi.advanceTimersByTimeAsync(25);
expect(refresh).toHaveBeenCalledTimes(1);
scheduler.notified(event);
scheduler.notified(event);
await vi.advanceTimersByTimeAsync(25);
expect(refresh).toHaveBeenCalledTimes(2);
scheduler.connected();
await vi.advanceTimersByTimeAsync(25);
expect(refresh).toHaveBeenCalledTimes(3);
scheduler.dispose();
});
});