feat(events): stream Redis invalidations over SSE
This commit is contained in:
@@ -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();
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user