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
Check · Review · Land · Live done — Landed and live in production.
scout/forge:scout/15380-flaky-test-500-entries-get-changelog-ans → main 0 commits fork
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 | */ | |
| 2 | 5 | import { afterAll, beforeAll, expect, test } from "bun:test"; |
| 3 | 6 | import { mkdtemp, rm } from "node:fs/promises"; |
| 4 | 7 | import { tmpdir } from "node:os"; |
| @@ -7,13 +10,14 @@ import { createApp, type App } from "../src/app.ts"; | ||
| 7 | 10 | import { createRepo } from "../src/actions/repos.ts"; |
| 8 | 11 | import { createUser } from "../src/core/users.ts"; |
| 9 | 12 | import { forgetLive, keepLive } from "../src/release/landings.ts"; |
| 13 | import { expectWork, pageWork, type PageWork } from "./helpers/work.ts"; | |
| 10 | 14 | import { serve, type Servers } from "../src/http/server.ts"; |
| 11 | 15 | |
| 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; | |
| 14 | 20 | 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; | |
| 17 | 21 | |
| 18 | 22 | let dataDir: string; |
| 19 | 23 | let app: App; |
| @@ -58,32 +62,27 @@ afterAll(async () => { | ||
| 58 | 62 | await rm(dataDir, { recursive: true, force: true }); |
| 59 | 63 | }); |
| 60 | 64 | |
| 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; | |
| 69 | 74 | } |
| 70 | 75 | |
| 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 () => { | |
| 74 | 77 | const warm = await fetch(`${servers.url}/changelog`); |
| 75 | 78 | expect(warm.status).toBe(200); |
| 76 | 79 | 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 }); | |
| 84 | 83 | }, 60_000); |
| 85 | 84 | |
| 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 () => { | |
| 87 | 86 | const repoId = app.db.query<{ id: string }, []>("SELECT id FROM repo WHERE name = 'forge'").get()!.id; |
| 88 | 87 | const chapter = app.db.query( |
| 89 | 88 | `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 | ||
| 99 | 98 | const body = await warm.text(); |
| 100 | 99 | expect(body).toContain('data-chapter="v1"'); |
| 101 | 100 | 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 }); | |
| 109 | 104 | }, 60_000); |
new above
offline