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
Check · Review · Land · Live done — Landed and live in production.
torque/forge:torque/5210-map-s-server-timing-names-its-phases-pas → main 1 commit fork
1 file
changed +44
−17
test/map-cache.test.ts +44 −17
| @@ -57,20 +57,36 @@ const MANY: Shape = { | ||
| 57 | 57 | /** What the page around the lanes reads, however many lanes there are. */ |
| 58 | 58 | const CHROME = 26; |
| 59 | 59 | |
| 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>(); | |
| 62 | 66 | afterAll(() => { |
| 63 | for (const f of fixtures) f.app.close(); | |
| 64 | 67 | for (const d of dirs) rmSync(d, { recursive: true, force: true }); |
| 65 | 68 | }, 60_000); |
| 66 | 69 | |
| 67 | async function boot(shape: Shape): Promise<{ f: Fixture; servers: Servers }> { | |
| 70 | async function boot(shape: Shape): Promise<{ f: Fixture; servers: Servers; release: () => void }> { | |
| 68 | 71 | const dir = mkdtempSync(join(tmpdir(), "forge-map-cache-")); |
| 69 | dirs.push(dir); | |
| 72 | dirs.add(dir); | |
| 70 | 73 | 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 }; | |
| 74 | 90 | } |
| 75 | 91 | |
| 76 | 92 | 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 | ||
| 81 | 97 | describe("/map on a many-lane fixture, warm", () => { |
| 82 | 98 | let servers: Servers; |
| 83 | 99 | let f: Fixture; |
| 100 | let release: (() => void) | undefined; | |
| 84 | 101 | beforeAll(async () => { |
| 85 | ({ f, servers } = await boot(MANY)); | |
| 102 | ({ f, servers, release } = await boot(MANY)); | |
| 86 | 103 | }, 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); | |
| 88 | 106 | |
| 89 | 107 | for (const who of ["owner", "stranger"] as const) { |
| 90 | 108 | 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", () => { | ||
| 140 | 158 | describe("/map after a write", () => { |
| 141 | 159 | let servers: Servers; |
| 142 | 160 | let f: Fixture; |
| 161 | let release: (() => void) | undefined; | |
| 143 | 162 | let owner: User; |
| 144 | 163 | let stranger: User; |
| 145 | 164 | const repoOf = (name: string): Repo => getRepo(f.app.db, "keeper", name)!; |
| 146 | 165 | beforeAll(async () => { |
| 147 | ({ f, servers } = await boot(SMALL)); | |
| 166 | ({ f, servers, release } = await boot(SMALL)); | |
| 148 | 167 | owner = getUserByName(f.app.db, "keeper")!; |
| 149 | 168 | stranger = getUserByName(f.app.db, "passerby")!; |
| 150 | 169 | }, 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); | |
| 152 | 172 | |
| 153 | 173 | test("an issue opened, then closed, shows on the next /map", async () => { |
| 154 | 174 | const repo = repoOf("plan-0"); |
| @@ -234,10 +254,12 @@ describe("the layout key", () => { | ||
| 234 | 254 | describe("/map's Server-Timing names its phases", () => { |
| 235 | 255 | let servers: Servers; |
| 236 | 256 | let f: Fixture; |
| 257 | let release: (() => void) | undefined; | |
| 237 | 258 | beforeAll(async () => { |
| 238 | ({ f, servers } = await boot(SMALL)); | |
| 259 | ({ f, servers, release } = await boot(SMALL)); | |
| 239 | 260 | }, 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); | |
| 241 | 263 | |
| 242 | 264 | for (const who of ["owner", "stranger"] as const) { |
| 243 | 265 | 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", () => { | ||
| 252 | 274 | const names = [...dur.keys()]; |
| 253 | 275 | expect(names.slice(-4), `${pass}: ${header}`).toEqual(["session", "lanes", "layout", "render"]); |
| 254 | 276 | 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); | |
| 258 | 285 | // No repository name rides in the header. |
| 259 | 286 | expect(header).not.toMatch(/\//); |
| 260 | 287 | } |
new above
offline