Public: anyone can read this; the crew can change it.

Full suite red: test/map-seed-timing.test.ts #15385

Merged opened this in answer to

Check · Review · Land · Live done — Landed and live in production.

Merged

scout/forge:scout/15383-full-suite-red-test-map-seed-timing-test → main 0 commits fork

  • Merged. scout/15383-full-suite-red-test-map-seed-timing-test was merged into main as 687c4ae.

Review

Sign in to review this change.
1 file changed +15 −9
test/map-seed-timing.test.ts +15 −9
@@ -80,22 +80,28 @@ afterAll(async () => {
8080 await rm(dataDir, { recursive: true, force: true });
8181 });
8282
83 /** The snapshot is keyed by the minute: start a cold/warm pair well clear of the next one. */
84 const clearOfMinute = async (): Promise<void> => {
85 const left = 60_000 - (Date.now() % 60_000);
86 if (left < 5_000) await Bun.sleep(left + 50);
83 /**
84 * The snapshot is keyed by the minute, so a cold/warm pair that straddles a
85 * minute boundary misses. Rather than sleeping out the boundary (up to 5 s,
86 * #15383), take the pair again when the minute turned between its reads.
87 */
88 const pair = async (): Promise<{ cold: Awaited<ReturnType<typeof get>>; warm: Awaited<ReturnType<typeof get>>; hits: number }> => {
89 for (let attempt = 0; ; attempt++) {
90 const minute = Math.floor(Date.now() / 60_000);
91 mapSnapshots(app.db).clear();
92 const cold = await get();
93 const hits = mapSnapshots(app.db).hits;
94 const warm = await get();
95 if (Math.floor(Date.now() / 60_000) === minute || attempt >= 2) return { cold, warm, hits };
96 }
8797 };
8898
8999 test("warm, the seed's map answers from its snapshot with the bytes of a cold build", async () => {
90 await clearOfMinute();
91 mapSnapshots(app.db).clear();
92 const cold = await get();
100 const { cold, warm, hits } = await pair();
93101 const data = JSON.parse(cold.body) as { issues: unknown[]; edges: unknown[]; pillars: { merged?: number }[] };
94102 expect(data.issues.length).toBeGreaterThan(500);
95103 expect(data.edges.length).toBe(400);
96104 expect(data.pillars.length).toBeGreaterThanOrEqual(9);
97 const hits = mapSnapshots(app.db).hits;
98 const warm = await get();
99105 expect(mapSnapshots(app.db).hits).toBe(hits + 1);
100106 expect(warm.body).toBe(cold.body);
101107 // Counted, not timed: a warm map is served from its snapshot, a hit each time and a few statements at most.

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs