mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-13 20:46:39 +00:00
test(memory): share short-timeout test helper
This commit is contained in:
@@ -1,6 +1,7 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { useFastShortTimeouts } from "../../test/helpers/fast-short-timeouts.js";
|
||||
import { installEmbeddingManagerFixture } from "./embedding-manager.test-harness.js";
|
||||
|
||||
const fx = installEmbeddingManagerFixture({
|
||||
@@ -88,22 +89,11 @@ describe("memory embedding batches", () => {
|
||||
return texts.map(() => [0, 1, 0]);
|
||||
});
|
||||
|
||||
const realSetTimeout = setTimeout;
|
||||
const setTimeoutSpy = vi.spyOn(global, "setTimeout").mockImplementation(((
|
||||
handler: TimerHandler,
|
||||
timeout?: number,
|
||||
...args: unknown[]
|
||||
) => {
|
||||
const delay = typeof timeout === "number" ? timeout : 0;
|
||||
if (delay > 0 && delay <= 2000) {
|
||||
return realSetTimeout(handler, 0, ...args);
|
||||
}
|
||||
return realSetTimeout(handler, delay, ...args);
|
||||
}) as typeof setTimeout);
|
||||
const restoreFastTimeouts = useFastShortTimeouts();
|
||||
try {
|
||||
await managerSmall.sync({ reason: "test" });
|
||||
} finally {
|
||||
setTimeoutSpy.mockRestore();
|
||||
restoreFastTimeouts();
|
||||
}
|
||||
|
||||
expect(calls).toBe(3);
|
||||
|
||||
Reference in New Issue
Block a user