Public: anyone can read this; the crew can change it.
A month of 5-minute roll-ups stays bounded in the boards ring #2489
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/2485-a-month-of-5-minute-roll-ups-stays-bound → main 1 commit fork
1 file
changed +28
−1
test/boards-sampler.test.ts +28 −1
| @@ -10,7 +10,7 @@ import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs"; | ||
| 10 | 10 | import { tmpdir } from "node:os"; |
| 11 | 11 | import { join } from "node:path"; |
| 12 | 12 | import { runQuery } from "../src/boards/query.ts"; |
| 13 | import { COARSE_KEEP_MS, FINE_KEEP_MS, record, rollUp, type Point } from "../src/boards/ring.ts"; | |
| 13 | import { COARSE_KEEP_MS, COARSE_MS, FINE_KEEP_MS, FINE_MS, record, rollUp, type Point } from "../src/boards/ring.ts"; | |
| 14 | 14 | import { gaps, pointsOf, readCounters, startSampler, type Paths } from "../src/boards/sampler.ts"; |
| 15 | 15 | import { SOURCES } from "../src/boards/sources.ts"; |
| 16 | 16 | import type { CellCounter } from "../src/apps/contain.ts"; |
| @@ -174,6 +174,33 @@ describe("the ring", () => { | ||
| 174 | 174 | const coarse = db.query<{ n: number }, []>("SELECT COUNT(*) AS n FROM machine_sample WHERE step = 300").get()!.n; |
| 175 | 175 | expect(coarse).toBe((2 * FINE_KEEP_MS) / 300_000); |
| 176 | 176 | }); |
| 177 | ||
| 178 | test("31 days of 15-s points keep at most 30 days of 5-min roll-ups, none past COARSE_KEEP_MS", () => { | |
| 179 | const db = fresh(); | |
| 180 | const days = 31; | |
| 181 | const end = T0 + days * 24 * 3_600_000; | |
| 182 | const started = performance.now(); | |
| 183 | // Real 15-s cadence, handed over one 5-min batch at a time, `now` at the batch's last point. | |
| 184 | for (let w = T0; w < end; w += COARSE_MS) { | |
| 185 | const batch: Point[] = []; | |
| 186 | for (let t = w; t < w + COARSE_MS; t += FINE_MS) { | |
| 187 | batch.push({ at: t, target: "forge", cpuCores: 1, memoryBytes: 1, load: null }); | |
| 188 | } | |
| 189 | record(db, batch, w + COARSE_MS - FINE_MS); | |
| 190 | } | |
| 191 | const now = end - FINE_MS; | |
| 192 | expect(performance.now() - started).toBeLessThan(5_000); | |
| 193 | ||
| 194 | const count = (step: number) => | |
| 195 | db.query<{ n: number }, [number]>("SELECT COUNT(*) AS n FROM machine_sample WHERE step = ? AND target = 'forge'").get(step)!.n; | |
| 196 | // 30 × 288 closed windows, plus the one the edge of the window falls in. | |
| 197 | expect(count(300)).toBeLessThanOrEqual(30 * 288 + 1); | |
| 198 | expect(count(300)).toBeGreaterThan(29 * 288); | |
| 199 | expect(count(15)).toBeLessThanOrEqual(FINE_KEEP_MS / FINE_MS + 1); | |
| 200 | expect(count(15)).toBeGreaterThan(FINE_KEEP_MS / FINE_MS - 20); | |
| 201 | const oldest = db.query<{ at: string }, []>("SELECT MIN(at) AS at FROM machine_sample WHERE step = 300").get()!.at; | |
| 202 | expect(Date.parse(oldest)).toBeGreaterThanOrEqual(now - COARSE_KEEP_MS); | |
| 203 | }); | |
| 177 | 204 | }); |
| 178 | 205 | |
| 179 | 206 | describe("the machine source", () => { |
new above
offline