Drop stale backlog events from /ws/live fanout
This commit is contained in:
parent
75fc6f9373
commit
89aaf63d34
4 changed files with 61 additions and 10 deletions
|
|
@ -1,6 +1,6 @@
|
|||
import { describe, expect, it } from "bun:test";
|
||||
import type { ClickHouseClient } from "@islandflow/storage";
|
||||
import { LiveStateManager, resolveGenericLiveLimits } from "../src/live";
|
||||
import { LiveStateManager, isLiveItemFresh, resolveGenericLiveLimits } from "../src/live";
|
||||
|
||||
const makeClickHouse = (): ClickHouseClient =>
|
||||
({
|
||||
|
|
@ -475,4 +475,31 @@ describe("LiveStateManager", () => {
|
|||
["MSFT-2025-01-17-300-C", "nbbo-other"]
|
||||
]);
|
||||
});
|
||||
|
||||
it("rejects stale ingest for freshness-gated channels", async () => {
|
||||
const manager = new LiveStateManager(makeClickHouse(), null);
|
||||
const now = Date.now();
|
||||
|
||||
await manager.ingest("equities", {
|
||||
source_ts: now - 60_000,
|
||||
ingest_ts: now - 59_999,
|
||||
seq: 1,
|
||||
trace_id: "eq-stale",
|
||||
ts: now - 60_000,
|
||||
underlying_id: "AAPL",
|
||||
price: 100,
|
||||
size: 10,
|
||||
exchange: "X",
|
||||
offExchangeFlag: false
|
||||
});
|
||||
|
||||
const snapshot = await manager.getSnapshot({ channel: "equities" });
|
||||
expect(snapshot.items).toHaveLength(0);
|
||||
});
|
||||
|
||||
it("exposes freshness helper for event fanout gating", () => {
|
||||
expect(isLiveItemFresh("options", { ts: 1000 }, 1010)).toBe(true);
|
||||
expect(isLiveItemFresh("options", { ts: 1000 }, 20_001)).toBe(false);
|
||||
expect(isLiveItemFresh("equity-joins", { source_ts: 1 }, 1_000_000)).toBe(true);
|
||||
});
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue