- Persist and remove the seeded run parent directory after perf runs - Add regression coverage for seed cleanup, percentile clamping, and RAF reset
Showing the changes to scripts (1 of 10 files). Show all
Unified · Split
| @@ -1,6 +1,6 @@ | ||
| 1 | 1 | import { spawn, type ChildProcess } from "node:child_process"; |
| 2 | 2 | import { once } from "node:events"; |
| 3 | −import { access } from "node:fs/promises"; | |
| 3 | +import { access, rm } from "node:fs/promises"; | |
| 4 | 4 | import { createServer } from "node:net"; |
| 5 | 5 | import { resolve } from "node:path"; |
| 6 | 6 | import { fileURLToPath } from "node:url"; |
| @@ -27,6 +27,7 @@ interface PerfSeedThreadSummary { · 20 unmodified lines | ||
| 27 | 27 | |
| 28 | 28 | interface PerfSeededState { |
| 29 | 29 | readonly scenarioId: PerfSeedScenarioId; |
| 30 | + readonly runParentDir: string; | |
| 30 | 31 | readonly baseDir: string; |
| 31 | 32 | readonly workspaceRoot: string; |
| 32 | 33 | readonly projectTitle: string | null; |
| @@ -252,6 +253,10 @@ async function stopChildProcess(process: ChildProcess): Promise<void> { · 219 unmodified lines | ||
| 252 | 253 | } |
| 253 | 254 | } |
| 254 | 255 | |
| 256 | +async function cleanupPerfRunDir(runParentDir: string): Promise<void> { | |
| 257 | + await rm(runParentDir, { recursive: true, force: true }); | |
| 258 | +} | |
| 259 | + | |
| 255 | 260 | function openUrl(url: string): void { |
| 256 | 261 | const command: [string, ...string[]] = |
| 257 | 262 | process.platform === "darwin" |
| @@ -339,6 +344,7 @@ async function main(): Promise<void> { · 81 unmodified lines | ||
| 339 | 344 | shuttingDown = true; |
| 340 | 345 | process.stdout.write(`\nReceived ${signal}. Stopping perf app...\n`); |
| 341 | 346 | await stopChildProcess(serverProcess); |
| 347 | + await cleanupPerfRunDir(seededState.runParentDir); | |
| 342 | 348 | process.exit(0); |
| 343 | 349 | }; |
| 344 | 350 | |
| @@ -349,17 +355,24 @@ async function main(): Promise<void> { · 4 unmodified lines | ||
| 349 | 355 | void shutdown("SIGTERM"); |
| 350 | 356 | }); |
| 351 | 357 | |
| 352 | − const url = `http://${options.host}:${port.toString()}`; | |
| 353 | − await waitForServerReady(url, serverProcess); | |
| 354 | − printSeedSummary(seededState, url, options.providerScenarioId); | |
| 358 | + try { | |
| 359 | + const url = `http://${options.host}:${port.toString()}`; | |
| 360 | + await waitForServerReady(url, serverProcess); | |
| 361 | + printSeedSummary(seededState, url, options.providerScenarioId); | |
| 355 | 362 | |
| 356 | − if (options.openBrowser) { | |
| 357 | − openUrl(url); | |
| 358 | − } | |
| 363 | + if (options.openBrowser) { | |
| 364 | + openUrl(url); | |
| 365 | + } | |
| 359 | 366 | |
| 360 | − const [exitCode] = (await once(serverProcess, "exit")) as [number | null]; | |
| 361 | − if (!shuttingDown) { | |
| 362 | − process.exit(exitCode ?? 0); | |
| 367 | + const [exitCode] = (await once(serverProcess, "exit")) as [number | null]; | |
| 368 | + if (!shuttingDown) { | |
| 369 | + await cleanupPerfRunDir(seededState.runParentDir); | |
| 370 | + process.exit(exitCode ?? 0); | |
| 371 | + } | |
| 372 | + } catch (error) { | |
| 373 | + await stopChildProcess(serverProcess); | |
| 374 | + await cleanupPerfRunDir(seededState.runParentDir); | |
| 375 | + throw error; | |
| 363 | 376 | } |
| 364 | 377 | } |
| 365 | 378 | |