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

Settings › Capacity's warm answer is read for its app time the way /search's is, and a test holds it #9744

Merged opened this

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

Merged

torque/forge:torque/9740-settings-capacity-s-warm-answer-is-read → main 1 commit fork

  • Merged. torque/9740-settings-capacity-s-warm-answer-is-read was merged into main as 5fd3417.

Review

Sign in to review this change.
1 file changed +41 −1
test/capacity-timing.test.ts +41 −1
@@ -1,5 +1,5 @@
11 /** The capacity settings page names its phases in Server-Timing (#3506). */
2 import { afterAll, beforeAll, expect, test } from "bun:test";
2 import { afterAll, beforeAll, expect, spyOn, test } from "bun:test";
33 import { mkdtemp, rm } from "node:fs/promises";
44 import { tmpdir } from "node:os";
55 import { join } from "node:path";
@@ -8,6 +8,21 @@ import { serve, type Servers } from "../src/http/server.ts";
88 import { seedAdmin } from "./helpers/admin.ts";
99 import { expectWork, requestStatements } from "./helpers/work.ts";
1010
11 /** The `app` phase of Server-Timing (the handler's own time, not the proxy's), or NaN. Reported, never judged (#4429). */
12 function appMs(res: Response): number {
13 const part = (res.headers.get("server-timing") ?? "").split(",").map((p) => p.trim()).find((p) => p.startsWith("app;"));
14 return Number(/dur=([\d.]+)/.exec(part ?? "")?.[1] ?? "NaN");
15 }
16
17 /** The calls in a spawn spy that ran git, whatever the argv shape. */
18 function gitCalls(calls: unknown[][]): number {
19 return calls.filter((c) => {
20 const first = c[0];
21 const argv = Array.isArray(first) ? first : (first as { cmd?: unknown } | undefined)?.cmd;
22 return Array.isArray(argv) && /(^|\/)git$/.test(String(argv[0]));
23 }).length;
24 }
25
1126 let dataDir = "";
1227 let app: App, servers: Servers, bearer = "";
1328
@@ -95,3 +110,28 @@ test("a warm capacity page costs a bounded number of statements, however many ch
95110 expectWork(some, { max: WARM_STATEMENTS });
96111 expect(more).toBe(some);
97112 });
113
114 // The warm answer, read the way /search's is (#9740, #9715): the `app` phase
115 // is sent and reported, never judged; the 50 ms bound is held as work — a
116 // bounded statement count and no git spawned (#4429).
117 test("a warm capacity page sends its app phase, stays under the statement ceiling and spawns no git", async () => {
118 const url = `${servers.url}/settings/capacity`;
119 const init = { headers: { authorization: `Bearer ${bearer}` } };
120 const first = await fetch(url, init);
121 expect(first.status).toBe(200);
122 await first.text();
123 const spawn = spyOn(Bun, "spawn");
124 const spawnSync = spyOn(Bun, "spawnSync");
125 try {
126 const second = await fetch(url, init);
127 const page = await second.text();
128 expect(second.status).toBe(200);
129 expect(page).toContain("Errors and refused calls");
130 expect(appMs(second)).not.toBeNaN();
131 expectWork(await requestStatements(app.db, url, init), { max: WARM_STATEMENTS });
132 expectWork(gitCalls(spawn.mock.calls) + gitCalls(spawnSync.mock.calls), { max: 0 });
133 } finally {
134 spawn.mockRestore();
135 spawnSync.mockRestore();
136 }
137 });

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs