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

Flaky test: 500 entries: GET /changelog answers in under 50 ms (median of 3 warm runs) #15381

Merged opened this in answer to

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

Merged

scout/forge:scout/15380-flaky-test-500-entries-get-changelog-ans → main 0 commits fork

  • Merged. scout/15380-flaky-test-500-entries-get-changelog-ans was merged into main as ccd02b1.

Review

Sign in to review this change.
1 file changed +26 −31
test/changelog-timing.test.ts +26 −31
@@ -1,4 +1,7 @@
1 /** GET /changelog stays instant as history grows: 500 release entries, fastest of warm GETs under budget, measured in CPU time (#10724). */
1 /**
2 * GET /changelog stays instant as history grows: 500 release entries, counted in work, not a clock
3 * (#10724).
4 */
25 import { afterAll, beforeAll, expect, test } from "bun:test";
36 import { mkdtemp, rm } from "node:fs/promises";
47 import { tmpdir } from "node:os";
@@ -7,13 +10,14 @@ import { createApp, type App } from "../src/app.ts";
710 import { createRepo } from "../src/actions/repos.ts";
811 import { createUser } from "../src/core/users.ts";
912 import { forgetLive, keepLive } from "../src/release/landings.ts";
13 import { expectWork, pageWork, type PageWork } from "./helpers/work.ts";
1014 import { serve, type Servers } from "../src/http/server.ts";
1115
12 /** The page's budget in milliseconds, as the palette's timing test states its own. */
13 const BUDGET_MS = 50;
16 /** Statements one warm GET may run: a constant, so an N+1 over 500 entries fails. */
17 const MAX_STATEMENTS = 40;
18 /** Git spawns one warm GET may run (measured 3 to 4, none per entry). */
19 const MAX_GIT = 8;
1420 const ENTRIES = 500;
15 /** Warm samples per test; the fastest is judged, so a stall from suites sharing the machine cannot fail the page (#13928). */
16 const RUNS = 9;
1721
1822 let dataDir: string;
1923 let app: App;
@@ -58,32 +62,27 @@ afterAll(async () => {
5862 await rm(dataDir, { recursive: true, force: true });
5963 });
6064
61 /** CPU milliseconds one GET costs this process (server and client share it): a stall from other suites sharing the machine adds wall time but no CPU, so the budget judges the page's work, not the machine's load (#15248). */
62 async function cpuOfGet(): Promise<number> {
63 const before = process.cpuUsage();
64 const res = await fetch(`${servers.url}/changelog`);
65 await res.arrayBuffer();
66 const d = process.cpuUsage(before);
67 expect(res.status).toBe(200);
68 return (d.user + d.system) / 1000;
65 /**
66 * What one warm GET /changelog costs in counted work: SQL statements and git spawns, never a clock
67 * (#7824).
68 */
69 async function work(): Promise<PageWork> {
70 const w = await pageWork(app.db, `${servers.url}/changelog`);
71 expect(w.status).toBe(200);
72 console.log(`changelog ${w.statements} statements, ${w.git} git spawns, ${w.ms.toFixed(1)} ms (printed, not judged)`);
73 return w;
6974 }
7075
71 const fastest = (xs: number[]) => Math.min(...xs);
72
73 test(`${ENTRIES} entries: GET /changelog answers in under ${BUDGET_MS} ms (fastest of ${RUNS} warm runs)`, async () => {
76 test(`${ENTRIES} entries: GET /changelog answers in constant work (counted work)`, async () => {
7477 const warm = await fetch(`${servers.url}/changelog`);
7578 expect(warm.status).toBe(200);
7679 expect(await warm.text()).toContain("Release entry");
77 const runs: number[] = [];
78 for (let i = 0; i < RUNS; i++) {
79 runs.push(await cpuOfGet());
80 }
81 const m = fastest(runs);
82 console.log(`changelog fastest ${m.toFixed(1)} cpu-ms over ${ENTRIES} entries (${runs.map((r) => r.toFixed(1)).join(", ")})`);
83 expect(m).toBeLessThan(BUDGET_MS);
80 const w = await work();
81 expectWork(w.statements, { max: MAX_STATEMENTS });
82 expectWork(w.git, { max: MAX_GIT });
8483 }, 60_000);
8584
86 test(`${ENTRIES} entries in two chapters: GET /changelog still answers in under ${BUDGET_MS} ms`, async () => {
85 test(`${ENTRIES} entries in two chapters: GET /changelog still answers in constant work`, async () => {
8786 const repoId = app.db.query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'forge'").get()!.id;
8887 const chapter = app.db.query(
8988 `INSERT INTO chapter (id, repo_id, name, means, state, position, created_at, opened_at, closed_at, tag_oid, notes) VALUES (?1, ?2, ?3, 'm', ?4, ?5, '2026-01-01T00:00:00Z', '2026-01-01T00:00:00Z', ?6, ?7, '')`,
@@ -99,11 +98,7 @@ test(`${ENTRIES} entries in two chapters: GET /changelog still answers in under
9998 const body = await warm.text();
10099 expect(body).toContain('data-chapter="v1"');
101100 expect(body).toContain("Between chapters");
102 const runs: number[] = [];
103 for (let i = 0; i < RUNS; i++) {
104 runs.push(await cpuOfGet());
105 }
106 const m = fastest(runs);
107 console.log(`changelog with chapters fastest ${m.toFixed(1)} cpu-ms over ${ENTRIES} entries (${runs.map((r) => r.toFixed(1)).join(", ")})`);
108 expect(m).toBeLessThan(BUDGET_MS);
101 const w = await work();
102 expectWork(w.statements, { max: MAX_STATEMENTS });
103 expectWork(w.git, { max: MAX_GIT });
109104 }, 60_000);

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs