mirror of
https://github.com/openclaw/openclaw.git
synced 2026-07-21 10:16:44 +00:00
test: tighten additional async polling (#108450)
This commit is contained in:
@@ -214,7 +214,8 @@ export async function waitForHttpBodyDeltas(
|
||||
notifications: Array<{ method: string; params?: unknown }>,
|
||||
count: number,
|
||||
): Promise<unknown[]> {
|
||||
for (let attempt = 0; attempt < 20; attempt += 1) {
|
||||
// Preserve the 500 ms failure budget while checking completed streams sooner.
|
||||
for (let attempt = 0; attempt < 100; attempt += 1) {
|
||||
const deltas = notifications
|
||||
.filter((notification) => notification.method === "http/request/bodyDelta")
|
||||
.map((notification) => notification.params);
|
||||
@@ -222,7 +223,7 @@ export async function waitForHttpBodyDeltas(
|
||||
return deltas;
|
||||
}
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 25);
|
||||
setTimeout(resolve, 5);
|
||||
});
|
||||
}
|
||||
throw new Error(`expected ${count} http body deltas`);
|
||||
|
||||
+2
-2
@@ -92,7 +92,7 @@ async function waitForPidFile(pathToCheck: string, timeoutMs: number): Promise<n
|
||||
return pid;
|
||||
}
|
||||
} catch {}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`Timed out waiting for a PID in ${pathToCheck}`);
|
||||
}
|
||||
@@ -104,7 +104,7 @@ async function waitForFile(pathToCheck: string, timeoutMs: number): Promise<void
|
||||
await readFile(pathToCheck);
|
||||
return;
|
||||
} catch {}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`Timed out waiting for ${pathToCheck}`);
|
||||
}
|
||||
|
||||
@@ -36,7 +36,7 @@ async function waitForPidFile(pathToCheck: string, timeoutMs: number): Promise<n
|
||||
return pid;
|
||||
}
|
||||
} catch {}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`Timed out waiting for a PID in ${pathToCheck}`);
|
||||
}
|
||||
@@ -47,7 +47,7 @@ async function waitForProcessExit(pid: number, timeoutMs: number): Promise<void>
|
||||
if (!isProcessRunning(pid)) {
|
||||
return;
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`Timed out waiting for process ${pid} to exit`);
|
||||
}
|
||||
|
||||
@@ -17,7 +17,7 @@ async function waitForFile(filePath: string, timeoutMs: number): Promise<void> {
|
||||
return;
|
||||
} catch {
|
||||
await new Promise((resolvePoll) => {
|
||||
setTimeout(resolvePoll, 25);
|
||||
setTimeout(resolvePoll, 5);
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -40,7 +40,7 @@ async function waitForDead(pid: number, timeoutMs: number): Promise<void> {
|
||||
return;
|
||||
}
|
||||
await new Promise((resolvePoll) => {
|
||||
setTimeout(resolvePoll, 25);
|
||||
setTimeout(resolvePoll, 5);
|
||||
});
|
||||
}
|
||||
throw new Error(`timed out waiting for pid ${pid} to exit`);
|
||||
|
||||
@@ -35,7 +35,7 @@ async function readPid(filePath: string, timeoutMs: number) {
|
||||
} catch {
|
||||
// retry until the process writes its pid
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`timeout waiting for pid in ${filePath}`);
|
||||
}
|
||||
@@ -46,7 +46,7 @@ async function waitForDead(pid: number, timeoutMs: number) {
|
||||
if (!isProcessRunning(pid)) {
|
||||
return;
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`process ${pid} still alive`);
|
||||
}
|
||||
|
||||
@@ -34,7 +34,7 @@ async function waitUntil(params: {
|
||||
throw new Error(`timed out waiting for ${params.description}`);
|
||||
}
|
||||
await new Promise<void>((resolve) => {
|
||||
setTimeout(resolve, 20);
|
||||
setTimeout(resolve, 5);
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
@@ -42,7 +42,7 @@ async function waitFor<T>(
|
||||
return value;
|
||||
}
|
||||
await new Promise((resolve) => {
|
||||
setTimeout(resolve, 50);
|
||||
setTimeout(resolve, 10);
|
||||
});
|
||||
}
|
||||
throw new Error(`timed out waiting for ${what}`);
|
||||
|
||||
@@ -43,7 +43,7 @@ async function waitForFile(pathToCheck: string, timeoutMs: number): Promise<void
|
||||
if (existsSync(pathToCheck)) {
|
||||
return;
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`Timed out waiting for ${pathToCheck}`);
|
||||
}
|
||||
|
||||
@@ -47,7 +47,7 @@ async function readPid(filePath: string, timeoutMs: number): Promise<number> {
|
||||
return pid;
|
||||
}
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`timeout waiting for a positive pid in ${filePath}`);
|
||||
}
|
||||
@@ -58,7 +58,7 @@ async function waitForDead(pid: number, timeoutMs: number): Promise<void> {
|
||||
if (!isProcessAlive(pid)) {
|
||||
return;
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`process still alive: ${pid}`);
|
||||
}
|
||||
|
||||
@@ -103,7 +103,7 @@ async function waitFor(predicate: () => boolean, timeoutMs = 5_000): Promise<voi
|
||||
if (predicate()) {
|
||||
return;
|
||||
}
|
||||
await delay(25);
|
||||
await delay(5);
|
||||
}
|
||||
throw new Error("condition was not met before timeout");
|
||||
}
|
||||
|
||||
@@ -312,7 +312,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -132,7 +132,7 @@ function waitForDead(pid: number, timeoutMs = 2_000): void {
|
||||
if (Date.now() - startedAt > timeoutMs) {
|
||||
throw new Error(`pid ${pid} is still alive`);
|
||||
}
|
||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 20);
|
||||
Atomics.wait(new Int32Array(new SharedArrayBuffer(4)), 0, 0, 5);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -145,14 +145,14 @@ function runPluginsSweepShell(script: string, env: NodeJS.ProcessEnv = {}) {
|
||||
}
|
||||
|
||||
async function waitForPortFile(portFile: string): Promise<number> {
|
||||
for (let attempt = 0; attempt < 50; attempt += 1) {
|
||||
for (let attempt = 0; attempt < 200; attempt += 1) {
|
||||
if (existsSync(portFile)) {
|
||||
const port = Number(readFileSync(portFile, "utf8"));
|
||||
if (Number.isInteger(port) && port > 0) {
|
||||
return port;
|
||||
}
|
||||
}
|
||||
await new Promise((resolve) => setTimeout(resolve, 20));
|
||||
await new Promise((resolve) => setTimeout(resolve, 5));
|
||||
}
|
||||
throw new Error(`timed out waiting for ${portFile}`);
|
||||
}
|
||||
|
||||
@@ -66,7 +66,7 @@ async function waitForFile(filePath: string, timeoutMs: number): Promise<void> {
|
||||
if (fs.existsSync(filePath)) {
|
||||
return;
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`timeout waiting for ${filePath}`);
|
||||
}
|
||||
@@ -77,7 +77,7 @@ async function waitForDead(pid: number, timeoutMs: number): Promise<void> {
|
||||
if (!isProcessAlive(pid)) {
|
||||
return;
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`process still alive: ${pid}`);
|
||||
}
|
||||
@@ -88,7 +88,7 @@ async function waitForNotRunning(pid: number, timeoutMs: number): Promise<void>
|
||||
if (!isProcessAlive(pid) || isProcessZombie(pid)) {
|
||||
return;
|
||||
}
|
||||
await sleep(25);
|
||||
await sleep(5);
|
||||
}
|
||||
throw new Error(`process still running: ${pid}`);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user