mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-10 08:12:43 +00:00
perf(test): optimize heavy suites and stabilize lock timing
This commit is contained in:
@@ -1,11 +1,19 @@
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
||||
import { waitForTransportReady } from "./transport-ready.js";
|
||||
|
||||
describe("waitForTransportReady", () => {
|
||||
beforeEach(() => {
|
||||
vi.useFakeTimers();
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
vi.useRealTimers();
|
||||
});
|
||||
|
||||
it("returns when the check succeeds and logs after the delay", async () => {
|
||||
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||
let attempts = 0;
|
||||
await waitForTransportReady({
|
||||
const readyPromise = waitForTransportReady({
|
||||
label: "test transport",
|
||||
timeoutMs: 500,
|
||||
logAfterMs: 120,
|
||||
@@ -20,22 +28,28 @@ describe("waitForTransportReady", () => {
|
||||
return { ok: false, error: "not ready" };
|
||||
},
|
||||
});
|
||||
|
||||
for (let i = 0; i < 5; i += 1) {
|
||||
await vi.advanceTimersByTimeAsync(80);
|
||||
}
|
||||
|
||||
await readyPromise;
|
||||
expect(runtime.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
it("throws after the timeout", async () => {
|
||||
const runtime = { log: vi.fn(), error: vi.fn(), exit: vi.fn() };
|
||||
await expect(
|
||||
waitForTransportReady({
|
||||
label: "test transport",
|
||||
timeoutMs: 200,
|
||||
logAfterMs: 0,
|
||||
logIntervalMs: 100,
|
||||
pollIntervalMs: 50,
|
||||
runtime,
|
||||
check: async () => ({ ok: false, error: "still down" }),
|
||||
}),
|
||||
).rejects.toThrow("test transport not ready");
|
||||
const waitPromise = waitForTransportReady({
|
||||
label: "test transport",
|
||||
timeoutMs: 200,
|
||||
logAfterMs: 0,
|
||||
logIntervalMs: 100,
|
||||
pollIntervalMs: 50,
|
||||
runtime,
|
||||
check: async () => ({ ok: false, error: "still down" }),
|
||||
});
|
||||
await vi.advanceTimersByTimeAsync(250);
|
||||
await expect(waitPromise).rejects.toThrow("test transport not ready");
|
||||
expect(runtime.error).toHaveBeenCalled();
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user