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

"/map's Server-Timing names its phases" passes every time on a loaded check machine #5238

Merged opened this

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

Merged

torque/forge:torque/5210-map-s-server-timing-names-its-phases-pas → main 1 commit fork

  • Merged. torque/5210-map-s-server-timing-names-its-phases-pas was merged into main as 7e9db90.

Review

Sign in to review this change.
1 file changed +44 −17
test/map-cache.test.ts +44 −17
@@ -57,20 +57,36 @@ const MANY: Shape = {
5757 /** What the page around the lanes reads, however many lanes there are. */
5858 const CHROME = 26;
5959
60 const dirs: string[] = [];
61 const fixtures: Fixture[] = [];
60 /**
61 * A fixture lives only as long as its describe: three held to the end of the
62 * file were ~19 MB of repositories on a check machine that ran out of disk
63 * (pull #5178), where a seed fails `git_init_failed` with nothing wrong here.
64 */
65 const dirs = new Set<string>();
6266 afterAll(() => {
63 for (const f of fixtures) f.app.close();
6467 for (const d of dirs) rmSync(d, { recursive: true, force: true });
6568 }, 60_000);
6669
67 async function boot(shape: Shape): Promise<{ f: Fixture; servers: Servers }> {
70 async function boot(shape: Shape): Promise<{ f: Fixture; servers: Servers; release: () => void }> {
6871 const dir = mkdtempSync(join(tmpdir(), "forge-map-cache-"));
69 dirs.push(dir);
72 dirs.add(dir);
7073 clearMapCache();
71 const f = await seedFixture(dir, shape);
72 fixtures.push(f);
73 return { f, servers: await serve(f.app) };
74 let f: Fixture | undefined;
75 let servers: Servers | undefined;
76 const release = () => {
77 servers?.stop();
78 f?.app.close();
79 rmSync(dir, { recursive: true, force: true });
80 dirs.delete(dir);
81 };
82 try {
83 f = await seedFixture(dir, shape);
84 servers = await serve(f.app);
85 } catch (error) {
86 release();
87 throw error;
88 }
89 return { f, servers, release };
7490 }
7591
7692 const get = async (servers: Servers, path: string, cookie: string): Promise<string> =>
@@ -81,10 +97,12 @@ const lanesIn = (page: string): number => page.split('<details id="lane-').lengt
8197 describe("/map on a many-lane fixture, warm", () => {
8298 let servers: Servers;
8399 let f: Fixture;
100 let release: (() => void) | undefined;
84101 beforeAll(async () => {
85 ({ f, servers } = await boot(MANY));
102 ({ f, servers, release } = await boot(MANY));
86103 }, 120_000);
87 afterAll(() => servers.stop(), 60_000);
104 // A boot that failed has nothing to stop: its own error is the one reported.
105 afterAll(() => release?.(), 60_000);
88106
89107 for (const who of ["owner", "stranger"] as const) {
90108 test(`${who}: a warm hit does a fraction of a cold build's work, statements within a fixed cost + 2 per lane`, async () => {
@@ -140,15 +158,17 @@ describe("/map on a many-lane fixture, warm", () => {
140158 describe("/map after a write", () => {
141159 let servers: Servers;
142160 let f: Fixture;
161 let release: (() => void) | undefined;
143162 let owner: User;
144163 let stranger: User;
145164 const repoOf = (name: string): Repo => getRepo(f.app.db, "keeper", name)!;
146165 beforeAll(async () => {
147 ({ f, servers } = await boot(SMALL));
166 ({ f, servers, release } = await boot(SMALL));
148167 owner = getUserByName(f.app.db, "keeper")!;
149168 stranger = getUserByName(f.app.db, "passerby")!;
150169 }, 60_000);
151 afterAll(() => servers.stop(), 60_000);
170 // A boot that failed has nothing to stop: its own error is the one reported.
171 afterAll(() => release?.(), 60_000);
152172
153173 test("an issue opened, then closed, shows on the next /map", async () => {
154174 const repo = repoOf("plan-0");
@@ -234,10 +254,12 @@ describe("the layout key", () => {
234254 describe("/map's Server-Timing names its phases", () => {
235255 let servers: Servers;
236256 let f: Fixture;
257 let release: (() => void) | undefined;
237258 beforeAll(async () => {
238 ({ f, servers } = await boot(SMALL));
259 ({ f, servers, release } = await boot(SMALL));
239260 }, 120_000);
240 afterAll(() => servers.stop(), 60_000);
261 // A boot that failed has nothing to stop: its own error is the one reported.
262 afterAll(() => release?.(), 60_000);
241263
242264 for (const who of ["owner", "stranger"] as const) {
243265 test(`${who}: session, lanes, layout and render follow app, and sum to no more than it`, async () => {
@@ -252,9 +274,14 @@ describe("/map's Server-Timing names its phases", () => {
252274 const names = [...dur.keys()];
253275 expect(names.slice(-4), `${pass}: ${header}`).toEqual(["session", "lanes", "layout", "render"]);
254276 expect(header.split(", ").every((p) => /^[a-z-]+;dur=\d+\.\d$/.test(p))).toBe(true);
255 const sum = ["session", "lanes", "layout", "render"].reduce((n, k) => n + dur.get(k)!, 0);
256 // Each is printed to a tenth of a millisecond, so allow that rounding.
257 expect(sum).toBeLessThanOrEqual(dur.get("app")! + 0.4);
277 const phases = ["session", "lanes", "layout", "render"];
278 const sum = phases.reduce((n, k) => n + dur.get(k)!, 0);
279 // The phases are disjoint stretches inside `app`, so their true sum is
280 // at most app's. `serverTiming` prints each with toFixed(1), off by at
281 // most half a tenth: four phases rounded up and app rounded down is
282 // the whole slack, 5 × 0.05 ms, with a hair for binary fractions.
283 const slack = (phases.length + 1) * 0.05 + 1e-9;
284 expect(sum, header).toBeLessThanOrEqual(dur.get("app")! + slack);
258285 // No repository name rides in the header.
259286 expect(header).not.toMatch(/\//);
260287 }

↑↓ navigate ↵ open ⌘↵ its app esc close

Keyboard shortcuts

Docs