mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-09 05:10:42 +00:00
Merged via squash.
Prepared head SHA: ec58a6212b
Co-authored-by: 100yenadmin <239388517+100yenadmin@users.noreply.github.com>
Co-authored-by: jalehman <550978+jalehman@users.noreply.github.com>
Reviewed-by: @jalehman
37 lines
1.1 KiB
TypeScript
37 lines
1.1 KiB
TypeScript
import { afterEach, describe, expect, it, vi } from "vitest";
|
|
import {
|
|
PLUGIN_HOST_CLEANUP_TIMEOUT_MS,
|
|
withPluginHostCleanupTimeout,
|
|
} from "./host-hook-cleanup-timeout.js";
|
|
|
|
describe("withPluginHostCleanupTimeout", () => {
|
|
afterEach(() => {
|
|
vi.restoreAllMocks();
|
|
});
|
|
|
|
it("unrefs cleanup timeout timers so pending cleanup does not keep the process alive", async () => {
|
|
const originalSetTimeout = globalThis.setTimeout;
|
|
const unref = vi.fn();
|
|
|
|
vi.spyOn(globalThis, "setTimeout").mockImplementation(((
|
|
callback: () => void,
|
|
timeout?: number,
|
|
) => {
|
|
const timer = originalSetTimeout(callback, timeout);
|
|
vi.spyOn(timer, "unref").mockImplementation(() => {
|
|
unref();
|
|
return timer;
|
|
});
|
|
return timer;
|
|
}) as typeof setTimeout);
|
|
|
|
await expect(withPluginHostCleanupTimeout("fast-cleanup", () => "ok")).resolves.toBe("ok");
|
|
|
|
expect(globalThis.setTimeout).toHaveBeenCalledWith(
|
|
expect.any(Function),
|
|
PLUGIN_HOST_CLEANUP_TIMEOUT_MS,
|
|
);
|
|
expect(unref).toHaveBeenCalledTimes(1);
|
|
});
|
|
});
|