From 4ae06b8c8e9828db692e389816b9456cdf64e48b Mon Sep 17 00:00:00 2001 From: Peter Steinberger Date: Wed, 15 Jul 2026 13:37:53 -0700 Subject: [PATCH] test: tighten more async polling (#108454) --- test/clawrouter-managed-gateway.e2e.test.ts | 5 +++-- test/scripts/clawhub-fixture-server.test.ts | 5 +++-- test/scripts/e2e-temp-state-dir.test.ts | 5 +++-- test/scripts/openclaw-cross-os-release-checks.test.ts | 9 +++++---- test/scripts/parallels-npm-update-smoke.test.ts | 4 ++-- test/scripts/parallels-smoke-model.test.ts | 2 +- test/scripts/plugin-gateway-gauntlet.test.ts | 2 +- test/scripts/plugin-lifecycle-measure.test.ts | 4 ++-- .../prepare-extension-package-boundary-artifacts.test.ts | 4 ++-- test/scripts/resolve-openclaw-package-candidate.test.ts | 4 ++-- test/scripts/run-oxlint.test.ts | 2 +- test/scripts/run-vitest.test.ts | 2 +- test/scripts/test-extension.test.ts | 2 +- test/scripts/test-live-shard.test.ts | 2 +- test/scripts/test-live.test.ts | 2 +- 15 files changed, 29 insertions(+), 25 deletions(-) diff --git a/test/clawrouter-managed-gateway.e2e.test.ts b/test/clawrouter-managed-gateway.e2e.test.ts index cf2855a49c4d..d3ecadb3d8a0 100644 --- a/test/clawrouter-managed-gateway.e2e.test.ts +++ b/test/clawrouter-managed-gateway.e2e.test.ts @@ -227,7 +227,8 @@ async function waitForGatewayReadiness( instance: OpenClawTestInstance, ): Promise<{ ready: boolean; failing: string[] }> { const url = `http://127.0.0.1:${instance.port}/readyz`; - for (let attempt = 0; attempt < 200; attempt += 1) { + // Preserve the 10-second readiness budget while detecting startup sooner. + for (let attempt = 0; attempt < 1_000; attempt += 1) { try { const response = await fetch(url); if (response.ok) { @@ -236,7 +237,7 @@ async function waitForGatewayReadiness( } catch { // The listener can open before startup readiness settles. } - await delay(50); + await delay(10); } throw new Error(`gateway did not become ready: ${instance.logs()}`); } diff --git a/test/scripts/clawhub-fixture-server.test.ts b/test/scripts/clawhub-fixture-server.test.ts index d04450d28ff8..87280c50867d 100644 --- a/test/scripts/clawhub-fixture-server.test.ts +++ b/test/scripts/clawhub-fixture-server.test.ts @@ -56,7 +56,8 @@ async function startFixtureServer(profile: string) { const readStderr = collectStream(child.stderr); servers.push(child); - for (let attempt = 0; attempt < 100; attempt += 1) { + // Preserve the 2.5-second startup budget while detecting the port file sooner. + for (let attempt = 0; attempt < 500; attempt += 1) { if (existsSync(portFile)) { const port = Number(readFileSync(portFile, "utf8")); if (Number.isInteger(port) && port > 0) { @@ -66,7 +67,7 @@ async function startFixtureServer(profile: string) { if (child.exitCode !== null) { throw new Error(`fixture server exited early: stdout=${readStdout()} stderr=${readStderr()}`); } - await delay(25); + await delay(5); } throw new Error(`fixture server did not write a port: stderr=${readStderr()}`); diff --git a/test/scripts/e2e-temp-state-dir.test.ts b/test/scripts/e2e-temp-state-dir.test.ts index df69472eec6b..00df9994ae09 100644 --- a/test/scripts/e2e-temp-state-dir.test.ts +++ b/test/scripts/e2e-temp-state-dir.test.ts @@ -17,11 +17,12 @@ import { describe, expect, it } from "vitest"; import { createE2eStateDir } from "../../scripts/e2e/lib/temp-state-dir.ts"; async function waitForFile(filePath: string) { - for (let attempt = 0; attempt < 100; attempt += 1) { + // Preserve the 2-second file budget while detecting child readiness sooner. + for (let attempt = 0; attempt < 400; attempt += 1) { if (existsSync(filePath)) { return; } - await delay(20); + await delay(5); } throw new Error(`Timed out waiting for ${filePath}`); } diff --git a/test/scripts/openclaw-cross-os-release-checks.test.ts b/test/scripts/openclaw-cross-os-release-checks.test.ts index 9190d3ad5904..baca94d71d77 100644 --- a/test/scripts/openclaw-cross-os-release-checks.test.ts +++ b/test/scripts/openclaw-cross-os-release-checks.test.ts @@ -119,7 +119,7 @@ async function waitForFile(filePath: string, timeoutMs: number): Promise { if (existsSync(filePath)) { return; } - await delay(25); + await delay(5); } throw new Error(`timeout waiting for ${filePath}`); } @@ -130,7 +130,7 @@ async function waitForDead(pid: number, timeoutMs: number): Promise { if (!isProcessAlive(pid)) { return; } - await delay(25); + await delay(5); } throw new Error(`process still alive: ${pid}`); } @@ -1704,11 +1704,12 @@ describe("scripts/openclaw-cross-os-release-checks", () => { await new Promise((resolvePromise) => { server.close(() => resolvePromise()); }); - for (let attempt = 0; attempt < 20; attempt += 1) { + // Preserve the 500 ms close budget while detecting port release sooner. + for (let attempt = 0; attempt < 100; attempt += 1) { if (!(await canConnectToLoopbackPort(port, 100))) { return; } - await delay(25); + await delay(5); } expect(await canConnectToLoopbackPort(port, 100)).toBe(false); }); diff --git a/test/scripts/parallels-npm-update-smoke.test.ts b/test/scripts/parallels-npm-update-smoke.test.ts index caf3909c6658..a5308b489b5a 100644 --- a/test/scripts/parallels-npm-update-smoke.test.ts +++ b/test/scripts/parallels-npm-update-smoke.test.ts @@ -55,7 +55,7 @@ async function waitForDead(pid: number, timeoutMs: number): Promise { return; } await new Promise((resolve) => { - setTimeout(resolve, 20); + setTimeout(resolve, 5); }); } throw new Error(`timeout waiting for pid ${pid} to exit`); @@ -68,7 +68,7 @@ async function waitFor(predicate: () => boolean, label: string, timeoutMs = 2_00 return; } await new Promise((resolve) => { - setTimeout(resolve, 20); + setTimeout(resolve, 5); }); } throw new Error(`timeout waiting for ${label}`); diff --git a/test/scripts/parallels-smoke-model.test.ts b/test/scripts/parallels-smoke-model.test.ts index 0c7cd5188538..cec0831cd7fa 100644 --- a/test/scripts/parallels-smoke-model.test.ts +++ b/test/scripts/parallels-smoke-model.test.ts @@ -214,7 +214,7 @@ async function waitFor(predicate: () => boolean, timeoutMs = 3_000): Promise { if (await predicate()) { return; } - await delay(25); + await delay(5); } throw new Error("condition was not met before timeout"); } diff --git a/test/scripts/plugin-lifecycle-measure.test.ts b/test/scripts/plugin-lifecycle-measure.test.ts index 9f6706c719ec..1a305db03eb4 100644 --- a/test/scripts/plugin-lifecycle-measure.test.ts +++ b/test/scripts/plugin-lifecycle-measure.test.ts @@ -48,7 +48,7 @@ function waitForPidExit(pid: number, timeoutMs: number): boolean { if (!pidExists(pid)) { return true; } - Atomics.wait(waitView, 0, 0, 25); + Atomics.wait(waitView, 0, 0, 5); } return !pidExists(pid); } @@ -61,7 +61,7 @@ function waitForPath(filePath: string, timeoutMs: number): boolean { if (existsSync(filePath)) { return true; } - Atomics.wait(waitView, 0, 0, 25); + Atomics.wait(waitView, 0, 0, 5); } return existsSync(filePath); } diff --git a/test/scripts/prepare-extension-package-boundary-artifacts.test.ts b/test/scripts/prepare-extension-package-boundary-artifacts.test.ts index fb2bc2f82e6d..758089bcb2b0 100644 --- a/test/scripts/prepare-extension-package-boundary-artifacts.test.ts +++ b/test/scripts/prepare-extension-package-boundary-artifacts.test.ts @@ -58,7 +58,7 @@ async function waitForFile(filePath: string, timeoutMs: number): Promise } catch { // Not created yet. } - await delay(25); + await delay(5); } throw new Error(`Timed out waiting for ${filePath}`); } @@ -81,7 +81,7 @@ async function waitForDead(pid: number, timeoutMs: number) { if (!isProcessAlive(pid)) { return; } - await delay(25); + await delay(5); } throw new Error(`Process ${pid} was still alive after ${timeoutMs}ms`); } diff --git a/test/scripts/resolve-openclaw-package-candidate.test.ts b/test/scripts/resolve-openclaw-package-candidate.test.ts index 16a88292e54c..68068cc35a52 100644 --- a/test/scripts/resolve-openclaw-package-candidate.test.ts +++ b/test/scripts/resolve-openclaw-package-candidate.test.ts @@ -68,7 +68,7 @@ async function waitForFile(filePath: string, timeoutMs: number): Promise { if (existsSync(filePath)) { return; } - await sleep(25); + await sleep(5); } throw new Error(`timeout waiting for ${filePath}`); } @@ -79,7 +79,7 @@ async function waitForDead(pid: number, timeoutMs: number): Promise { if (!isProcessAlive(pid)) { return; } - await sleep(25); + await sleep(5); } throw new Error(`process still alive: ${pid}`); } diff --git a/test/scripts/run-oxlint.test.ts b/test/scripts/run-oxlint.test.ts index 171b7d01a254..2294dfa0e30e 100644 --- a/test/scripts/run-oxlint.test.ts +++ b/test/scripts/run-oxlint.test.ts @@ -33,7 +33,7 @@ async function waitFor(predicate: () => boolean, timeoutMs: number): Promise { - setTimeout(resolvePoll, 25); + setTimeout(resolvePoll, 5); }); } throw new Error("condition was not met before timeout"); diff --git a/test/scripts/run-vitest.test.ts b/test/scripts/run-vitest.test.ts index a77af454d12c..3edbed17dc45 100644 --- a/test/scripts/run-vitest.test.ts +++ b/test/scripts/run-vitest.test.ts @@ -1016,7 +1016,7 @@ async function waitFor(condition: () => boolean, timeoutMs = 3_000) { if (Date.now() - startedAt > timeoutMs) { throw new Error("timed out waiting for condition"); } - await delay(25); + await delay(5); } } diff --git a/test/scripts/test-extension.test.ts b/test/scripts/test-extension.test.ts index 1daf663733fd..c3cfa4c104fb 100644 --- a/test/scripts/test-extension.test.ts +++ b/test/scripts/test-extension.test.ts @@ -993,7 +993,7 @@ async function waitFor(condition: () => boolean, timeoutMs = 3_000): Promise timeoutMs) { throw new Error("timed out waiting for condition"); } - await delay(25); + await delay(5); } } diff --git a/test/scripts/test-live-shard.test.ts b/test/scripts/test-live-shard.test.ts index e8d0455f8e84..9d949c1c5dcc 100644 --- a/test/scripts/test-live-shard.test.ts +++ b/test/scripts/test-live-shard.test.ts @@ -568,7 +568,7 @@ async function waitFor(condition: () => boolean, timeoutMs: number): Promise timeoutMs) { throw new Error("timed out waiting for condition"); } - await delay(25); + await delay(5); } } diff --git a/test/scripts/test-live.test.ts b/test/scripts/test-live.test.ts index 36ca01dbfc7f..c73ca9756916 100644 --- a/test/scripts/test-live.test.ts +++ b/test/scripts/test-live.test.ts @@ -249,7 +249,7 @@ async function waitFor(condition: () => boolean, timeoutMs = 3_000) { if (Date.now() - startedAt > timeoutMs) { throw new Error("timed out waiting for condition"); } - await delay(25); + await delay(5); } }