Files
openclaw/src/plugins/host-hook-cleanup-timeout.test.ts
Eva 8afc9ef73c [plugin sdk] Harden finalize retry and run context cleanup (#75600)
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
2026-05-04 07:04:22 -07:00

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);
});
});