chore: remove gate-lease.test.mjs temp directories after the suite
Closes #2346 `freshDir()` now records every `gate-lease-test-*` directory it creates and a top-level `after` hook removes them all once the file's tests are done. Every test that starts a child awaits its exit before asserting, so nothing holds a lock inside them by then. Measured on one `npm run test:scripts`: 14 new directories left in $TMPDIR before, 0 after; 647/647 tests pass in both arms. No assertion changed. Co-Authored-By: Claude Fable 5.1 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01PsmUAZ6aLUAFqenjJKSSRp Signed-off-by: cliffhall <cliff@futurescale.com>
This commit is contained in:
parent
1030f3d8f9
commit
1ebf11b660
1 changed files with 19 additions and 3 deletions
|
|
@ -5,7 +5,7 @@
|
|||
// behind (or block) a developer's actual gate. Run via `npm run test:scripts`
|
||||
// (node:test; the root has no vitest harness).
|
||||
|
||||
import { test } from "node:test";
|
||||
import { after, test } from "node:test";
|
||||
import assert from "node:assert/strict";
|
||||
import { spawn } from "node:child_process";
|
||||
import {
|
||||
|
|
@ -41,11 +41,27 @@ import {
|
|||
|
||||
const SCRIPT = fileURLToPath(new URL("./gate-lease.mjs", import.meta.url));
|
||||
|
||||
/** A fresh lease directory per test, so tests never contend with each other. */
|
||||
/**
|
||||
* A fresh lease directory per test, so tests never contend with each other.
|
||||
* Each one is recorded so the suite can remove it once every test is done
|
||||
* (#2346): one hook, rather than a try/finally in each of the fourteen tests,
|
||||
* and it runs whether a test passed, failed, or threw before its own cleanup.
|
||||
*/
|
||||
const createdDirs = [];
|
||||
function freshDir() {
|
||||
return mkdtempSync(join(tmpdir(), "gate-lease-test-"));
|
||||
const dir = mkdtempSync(join(tmpdir(), "gate-lease-test-"));
|
||||
createdDirs.push(dir);
|
||||
return dir;
|
||||
}
|
||||
|
||||
// Runs once all tests in the file have finished. Every test that starts a
|
||||
// child (or the wrapper) awaits its exit before asserting, so by now nothing
|
||||
// is holding a lock inside any of these directories, and a stray lock or
|
||||
// holder record a test left on purpose is just a directory to remove.
|
||||
after(() => {
|
||||
for (const dir of createdDirs) rmSync(dir, { recursive: true, force: true });
|
||||
});
|
||||
|
||||
function collectLog() {
|
||||
const lines = [];
|
||||
return { lines, log: (line) => lines.push(line) };
|
||||
|
|
|
|||
Loading…
Reference in a new issue