Files
apes-sidebar/tests/temp-tree.ts
T
unsc9 9f92bff245 test: widen the Windows temp-tree cleanup retry budget
The ci-windows lane failed in archive.spec.ts's afterEach with ENOTEMPTY after the test had passed. The same cleanup flaked on 2026-10-15; the existing 10x50 ms retry budget is too short on a loaded runner. Raise it to 30x100 ms; POSIX still succeeds on the first attempt.
2026-10-28 22:32:03 +08:00

30 lines
1.4 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
/**
* Temp-tree removal for specs that spawn real child processes or hold OS
* handles (zip / tar / git / fd / rg / powershell / `fs.watch`) inside the
* tree they are about to delete.
*
* `rmSync(path, { recursive: true, force: true })` is not enough on Windows:
* a child that was just killed, or a watcher that was just closed, can still
* hold a handle for a few milliseconds, and the removal then fails with
* ENOTEMPTY / EBUSY / EPERM **from the cleanup of a test that had already
* passed** — which is how the Windows lane went red on 2026-10-15
* (`tests/archive.spec.ts`'s afterEach, `ENOTEMPTY: rmdir …archives-pvpAWR`,
* on a run where only that cleanup failed and 2466 tests passed).
*
* `maxRetries` + `retryDelay` is Node's own remedy for exactly this, so every
* risky cleanup goes through here instead of repeating the retry inline.
* The same archive cleanup flaked again on 2026-10-28 under a loaded runner,
* so the budget now covers a slower handle release than the original 10×50 ms.
* POSIX runs are unaffected: the first attempt succeeds and no retry happens.
*/
import { rmSync } from 'node:fs'
/**
* Remove one file or directory tree, retrying while a just-closed handle is
* still being released by the OS.
* @param path - file or directory to remove (missing paths are ignored).
*/
export function removeTree(path: string): void {
rmSync(path, { recursive: true, force: true, maxRetries: 30, retryDelay: 100 })
}