From 577f086658c8e2b8e2d47dd1c0804c5ba9ed989b Mon Sep 17 00:00:00 2001 From: Chris Tate Date: Wed, 28 Oct 2026 12:49:21 -0500 Subject: [PATCH] Space the timer delays in two order-sensitive tests and raise the static-spatial timeout mock-timers' "named and namespace imports keep the loop's timers" and 6811-node-island-uncaught-listener check the order in which real timers fire, with delays 1 to 5 ms apart that are scheduled one after another. On a busy runner more time than that can pass between scheduling two of them, and the order flips in either lane: the sanitized node:test run saw Node's reference print 'named promise' first, and the sanitized llvm-differential run saw 'island timer 1' before 'native timer after'. The delays are now 100 ms apart in mock-timers (100, 200, 300) and the island's timers (150, 250) start 100 ms after the native ones (10, 50). Node prints the same output as before. static-spatial bundles three.js and builds it with the sanitizer, which passed the default 300 s test timeout on a busy runner. Its cases take three.test.ts's 1200 s timeout. --- .../corpus/6811-node-island-uncaught-listener/island.cjs | 4 ++-- tests/corpus/6811-node-island-uncaught-listener/main.mjs | 6 ++++-- tests/fixtures/node-test/cases/mock-timers.ts | 9 ++++++--- tests/harness/static-spatial.test.ts | 3 +++ 4 files changed, 15 insertions(+), 7 deletions(-) diff --git a/tests/corpus/6811-node-island-uncaught-listener/island.cjs b/tests/corpus/6811-node-island-uncaught-listener/island.cjs index 650c7f3f3..ae988f8c0 100644 --- a/tests/corpus/6811-node-island-uncaught-listener/island.cjs +++ b/tests/corpus/6811-node-island-uncaught-listener/island.cjs @@ -1,4 +1,4 @@ exports.timers = () => { - setTimeout(() => console.log("island timer 1"), 15); - setTimeout(() => console.log("island timer 2"), 40); + setTimeout(() => console.log("island timer 1"), 150); + setTimeout(() => console.log("island timer 2"), 250); }; diff --git a/tests/corpus/6811-node-island-uncaught-listener/main.mjs b/tests/corpus/6811-node-island-uncaught-listener/main.mjs index 9195e7baa..05397c2e4 100644 --- a/tests/corpus/6811-node-island-uncaught-listener/main.mjs +++ b/tests/corpus/6811-node-island-uncaught-listener/main.mjs @@ -7,12 +7,14 @@ import { callSync } from "@scriptc/node"; process.on("uncaughtException", (error) => { console.log("caught", error.message); }); +// The island's timers (150 and 250 ms) are scheduled before these (10 and +// 50 ms), with gaps wide enough that a slow run keeps the delay order. callSync("./island.cjs", "timers"); setTimeout(() => { console.log("native timer throws"); throw new Error("native boom"); -}, 5); -setTimeout(() => console.log("native timer after"), 10); +}, 10); +setTimeout(() => console.log("native timer after"), 50); setImmediate(() => { queueMicrotask(() => { throw new Error("from a microtask"); diff --git a/tests/fixtures/node-test/cases/mock-timers.ts b/tests/fixtures/node-test/cases/mock-timers.ts index 1e5e5883f..c31b16aa1 100644 --- a/tests/fixtures/node-test/cases/mock-timers.ts +++ b/tests/fixtures/node-test/cases/mock-timers.ts @@ -271,21 +271,24 @@ describe("imports", () => { it("named and namespace imports keep the loop's timers", async (t) => { t.mock.timers.enable({ apis: ["setTimeout"] }); const log: string[] = []; + // The three timers are real and scheduled one after another, so their + // delays are 100 ms apart: a slow run (a sanitized build on a busy + // machine) still sees them fire in delay order. await Promise.all([ - sleep(5).then(() => { + sleep(300).then(() => { log.push("named promise"); }), new Promise((resolve) => namedSetTimeout(() => { log.push("named"); resolve(); - }, 2), + }, 100), ), new Promise((resolve) => timersNamespace.setTimeout(() => { log.push("namespace"); resolve(); - }, 3), + }, 200), ), ]); t.mock.timers.tick(10); diff --git a/tests/harness/static-spatial.test.ts b/tests/harness/static-spatial.test.ts index b0f40ee4e..e9bb23b1c 100644 --- a/tests/harness/static-spatial.test.ts +++ b/tests/harness/static-spatial.test.ts @@ -29,6 +29,9 @@ const cases = [ ].flatMap((fixture) => ["native", "wasm32-wasi"].map((target) => ({ fixture, target }))); test.for(cases)( "published $fixture runs statically on $target", + // Bundling three.js and building it with the sanitizer can pass the + // default 300 s on a busy runner, as in three.test.ts. + { timeout: 1_200_000 }, async ({ fixture, target }, context) => { if (target === "wasm32-wasi" && !hasZig) context.skip(); const dir = await mkdtemp("/tmp/scriptc-spatial-");