From ba81f67930cce689b1444c03dc3a4c0dbf13e97b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Miguel=20=C3=81ngel?= Date: Sat, 21 Nov 2026 08:27:21 +0000 Subject: [PATCH] test(studio-server): a held save proves it never sleeps the thread, not a 100 ms stall bound (#8359) --- .../src/routes/files.heldFile.test.ts | 27 +++++-------------- 1 file changed, 7 insertions(+), 20 deletions(-) diff --git a/packages/studio-server/src/routes/files.heldFile.test.ts b/packages/studio-server/src/routes/files.heldFile.test.ts index 43bbbc4771..99a0514bbd 100644 --- a/packages/studio-server/src/routes/files.heldFile.test.ts +++ b/packages/studio-server/src/routes/files.heldFile.test.ts @@ -176,22 +176,6 @@ function holdFor(file: string, ms: number) { } /** The longest the event loop went without running a 5 ms timer while `work` ran. */ -async function longestStall(work: () => Promise) { - let last = performance.now(); - let longest = 0; - const tick = setInterval(() => { - const now = performance.now(); - longest = Math.max(longest, now - last); - last = now; - }, 5); - try { - await work(); - } finally { - clearInterval(tick); - } - return longest; -} - describe("an element edit while Windows briefly holds the file", () => { const edited = '
kept
'; @@ -237,13 +221,16 @@ describe("an element edit while Windows briefly holds the file", () => { }, 10_000); // fails without the fix: each retry slept the whole process, up to 640 ms in one go. - it("keeps the app answering while it waits", async () => { + // fails without the fix: the save slept the thread between retries (Atomics.wait), so the app froze for the hold. + it("keeps the app answering while it waits: it never sleeps the thread", async () => { const { file, remove } = fixture("held.html"); writeFileSync(file, `${edited}

tag

`); holdFor(file, 1_500); - expect( - await longestStall(async () => expect((await remove("gone")).status).toBe(200)), - ).toBeLessThan(100); + const sleeps = vi.spyOn(Atomics, "wait"); + cleanups.push(() => sleeps.mockRestore()); + const answer = await remove("gone"); + expect(sleeps).not.toHaveBeenCalled(); + expect(answer.status).toBe(200); }, 10_000); it("answers 423 busy once the hold outlasts the wait, reports it once, and leaves the file as it was", async () => {