From 10ccebb052d01036e65cf15d234a55847cd0234e Mon Sep 17 00:00:00 2001 From: unsc9 <438590997@qq.com> Date: Thu, 29 Oct 2026 10:22:14 +0800 Subject: [PATCH] test: let detached archive packs land before cleanup --- tests/archive.spec.ts | 6 +++++- tests/temp-tree.ts | 5 +++-- 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/archive.spec.ts b/tests/archive.spec.ts index 7b470512..e0d47664 100644 --- a/tests/archive.spec.ts +++ b/tests/archive.spec.ts @@ -268,12 +268,16 @@ beforeEach(() => { }) afterEach(async () => { + // `start()` launches `pack()` detached; give its open/spawn a beat to land + // before dispose kills the child. Disposing first lets a late open create a + // temp file AFTER the cleanup below has already walked the tree. + await new Promise(resolve => setTimeout(resolve, 50)) // Before the mocks go: `dispose()` kills through a fake whose `kill` is a // `vi.fn`, and those implementations do not survive a restore. for (const tasks of tables.splice(0)) tasks.dispose() // A killed child closes asynchronously; let the close land (and the packer // close its descriptor) before the directories underneath it disappear. - await new Promise(resolve => setTimeout(resolve, 0)) + await new Promise(resolve => setTimeout(resolve, 50)) for (const [key, value] of Object.entries(savedTmp)) { if (value === undefined) delete process.env[key] else process.env[key] = value diff --git a/tests/temp-tree.ts b/tests/temp-tree.ts index 1ae94736..35515f0b 100644 --- a/tests/temp-tree.ts +++ b/tests/temp-tree.ts @@ -14,7 +14,8 @@ * `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. + * so the budget now covers a slower handle release than the original 10×50 ms; + * the Windows lane still hit it once on 2026-10-29, hence the 6 s budget. * POSIX runs are unaffected: the first attempt succeeds and no retry happens. */ import { rmSync } from 'node:fs' @@ -25,5 +26,5 @@ import { rmSync } from 'node:fs' * @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 }) + rmSync(path, { recursive: true, force: true, maxRetries: 60, retryDelay: 100 }) }