mirror of
https://github.com/openclaw/openclaw.git
synced 2026-06-08 04:22:54 +00:00
fix(gateway-client): clamp readiness intervals
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { afterEach, describe, expect, it, vi } from "vitest";
|
||||
import { waitForEventLoopReady } from "./event-loop-ready.js";
|
||||
import { MAX_SAFE_TIMEOUT_DELAY_MS } from "./timeouts.js";
|
||||
|
||||
describe("waitForEventLoopReady", () => {
|
||||
afterEach(() => {
|
||||
@@ -25,4 +26,26 @@ describe("waitForEventLoopReady", () => {
|
||||
checks: 2,
|
||||
});
|
||||
});
|
||||
|
||||
it("clamps oversized readiness intervals before scheduling", async () => {
|
||||
vi.useFakeTimers();
|
||||
const setTimeoutSpy = vi.spyOn(globalThis, "setTimeout");
|
||||
|
||||
const readiness = waitForEventLoopReady({
|
||||
maxWaitMs: Number.MAX_SAFE_INTEGER,
|
||||
intervalMs: Number.MAX_SAFE_INTEGER,
|
||||
consecutiveReadyChecks: 1,
|
||||
});
|
||||
|
||||
expect(setTimeoutSpy).toHaveBeenLastCalledWith(expect.any(Function), MAX_SAFE_TIMEOUT_DELAY_MS);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(1);
|
||||
expect(setTimeoutSpy).toHaveBeenCalledTimes(1);
|
||||
|
||||
await vi.advanceTimersByTimeAsync(MAX_SAFE_TIMEOUT_DELAY_MS - 1);
|
||||
await expect(readiness).resolves.toMatchObject({
|
||||
ready: true,
|
||||
checks: 1,
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -31,7 +31,7 @@ export async function waitForEventLoopReady(
|
||||
const maxWaitMs = resolveFiniteTimeoutDelayMs(options.maxWaitMs, DEFAULT_MAX_WAIT_MS, {
|
||||
minMs: 0,
|
||||
});
|
||||
const intervalMs = resolvePositiveInteger(options.intervalMs, DEFAULT_INTERVAL_MS);
|
||||
const intervalMs = resolveFiniteTimeoutDelayMs(options.intervalMs, DEFAULT_INTERVAL_MS);
|
||||
const driftThresholdMs = resolvePositiveInteger(
|
||||
options.driftThresholdMs,
|
||||
DEFAULT_DRIFT_THRESHOLD_MS,
|
||||
|
||||
Reference in New Issue
Block a user