From 9b9d13c246b2b8445a2ebd4be81cbd516bd3cd21 Mon Sep 17 00:00:00 2001 From: Alistair Smith Date: Tue, 20 Oct 2026 10:14:21 +0900 Subject: [PATCH 1/2] test: wait for a killed process to let go of a temp folder on windows, and use the last url of bun bake --check --- test/cli/bake/bake.test.ts | 18 +++++++++++++++--- test/harness.ts | 13 ++++++++++++- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/test/cli/bake/bake.test.ts b/test/cli/bake/bake.test.ts index 8e6b9a0bc2ec..c2a029f09c9b 100644 --- a/test/cli/bake/bake.test.ts +++ b/test/cli/bake/bake.test.ts @@ -448,9 +448,21 @@ test.concurrent.each([ join(String(dir), "app/server.ts"), `declare const Response: any;\nconst count: number = 1;\nexport default { fetch: () => new Response(String(count)) };\n`, ); - const [, url] = await output.waitFor(/url: (http:\/\/\S+)/); - - expect(await get(url, "/missing")).toBe("200 1"); + await output.waitFor(/url: (http:\/\/\S+)/); + + // One save can start the process twice on Windows, and each start prints its own port. + const deadline = Date.now() + 10_000; + let response: string; + while (true) { + const url = [...output.text.matchAll(/url: (http:\/\/\S+)/g)].at(-1)![1]; + try { + response = await get(url, "/missing"); + break; + } catch (error) { + if (Date.now() > deadline) throw error; + } + } + expect(response).toBe("200 1"); }); // Creating a symlink on Windows needs a privilege that CI does not have. diff --git a/test/harness.ts b/test/harness.ts index 584e36bda2cc..bcda4d3ca350 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -611,7 +611,18 @@ export function tempDirWithFiles( class DisposableString extends String { [Symbol.dispose]() { - fs.rmSync(this + "", { recursive: true, force: true }); + // On Windows a process that was just killed can hold the folder for a moment: a child that a job + // object ends after its parent, for one. `rmSync` does not act on `maxRetries`. + const deadline = Date.now() + 5000; + while (true) { + try { + fs.rmSync(this + "", { recursive: true, force: true }); + return; + } catch (error: any) { + if (!isWindows || error?.code !== "EBUSY" || Date.now() > deadline) throw error; + Bun.sleepSync(50); + } + } } [Symbol.asyncDispose]() { return fs.promises.rm(this + "", { recursive: true, force: true }); From f52d21e08d2c536d403d94c9e2921a2c7f4a75c8 Mon Sep 17 00:00:00 2001 From: Alistair Smith Date: Tue, 20 Oct 2026 10:36:58 +0900 Subject: [PATCH 2/2] test: retry the --check request only on windows, and the async temp folder cleanup too --- test/cli/bake/bake.test.ts | 19 +++++++++---------- test/harness.ts | 14 +++++++++++--- 2 files changed, 20 insertions(+), 13 deletions(-) diff --git a/test/cli/bake/bake.test.ts b/test/cli/bake/bake.test.ts index c2a029f09c9b..734d25ce2cc3 100644 --- a/test/cli/bake/bake.test.ts +++ b/test/cli/bake/bake.test.ts @@ -448,19 +448,18 @@ test.concurrent.each([ join(String(dir), "app/server.ts"), `declare const Response: any;\nconst count: number = 1;\nexport default { fetch: () => new Response(String(count)) };\n`, ); - await output.waitFor(/url: (http:\/\/\S+)/); + const [, url] = await output.waitFor(/url: (http:\/\/\S+)/); // One save can start the process twice on Windows, and each start prints its own port. + if (!isWindows) { + expect(await get(url, "/missing")).toBe("200 1"); + return; + } const deadline = Date.now() + 10_000; - let response: string; - while (true) { - const url = [...output.text.matchAll(/url: (http:\/\/\S+)/g)].at(-1)![1]; - try { - response = await get(url, "/missing"); - break; - } catch (error) { - if (Date.now() > deadline) throw error; - } + let response = ""; + while (response !== "200 1" && Date.now() < deadline) { + const latest = [...output.text.matchAll(/url: (http:\/\/\S+)/g)].at(-1)![1]; + response = await get(latest, "/missing").catch(String); } expect(response).toBe("200 1"); }); diff --git a/test/harness.ts b/test/harness.ts index bcda4d3ca350..a36d06b29e84 100644 --- a/test/harness.ts +++ b/test/harness.ts @@ -620,12 +620,20 @@ class DisposableString extends String { return; } catch (error: any) { if (!isWindows || error?.code !== "EBUSY" || Date.now() > deadline) throw error; - Bun.sleepSync(50); + sleepSync(50); } } } - [Symbol.asyncDispose]() { - return fs.promises.rm(this + "", { recursive: true, force: true }); + async [Symbol.asyncDispose]() { + const deadline = Date.now() + 5000; + while (true) { + try { + return await fs.promises.rm(this + "", { recursive: true, force: true }); + } catch (error: any) { + if (!isWindows || error?.code !== "EBUSY" || Date.now() > deadline) throw error; + await Bun.sleep(50); + } + } } }