mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-18 03:20:45 +00:00
test: tighten vitest process listener assertions
This commit is contained in:
@@ -7,6 +7,23 @@ import {
|
||||
} from "../../scripts/vitest-process-group.mjs";
|
||||
|
||||
describe("vitest process group helpers", () => {
|
||||
function getListenerSet(listeners: Map<string, Set<() => void>>, event: string) {
|
||||
const set = listeners.get(event);
|
||||
expect(set).toBeDefined();
|
||||
if (!set) {
|
||||
throw new Error(`expected ${event} listener set`);
|
||||
}
|
||||
return set;
|
||||
}
|
||||
|
||||
function expectListenerCount(
|
||||
listeners: Map<string, Set<() => void>>,
|
||||
event: string,
|
||||
count: number,
|
||||
) {
|
||||
expect(getListenerSet(listeners, event).size).toBe(count);
|
||||
}
|
||||
|
||||
it("uses detached process groups on non-Windows hosts", () => {
|
||||
expect(shouldUseDetachedVitestProcessGroup("darwin")).toBe(true);
|
||||
expect(shouldUseDetachedVitestProcessGroup("linux")).toBe(true);
|
||||
@@ -84,17 +101,17 @@ describe("vitest process group helpers", () => {
|
||||
kill,
|
||||
});
|
||||
|
||||
expect(listeners.get("SIGINT")?.size).toBe(1);
|
||||
expect(listeners.get("SIGTERM")?.size).toBe(1);
|
||||
expect(listeners.get("exit")?.size).toBe(1);
|
||||
expectListenerCount(listeners, "SIGINT", 1);
|
||||
expectListenerCount(listeners, "SIGTERM", 1);
|
||||
expectListenerCount(listeners, "exit", 1);
|
||||
|
||||
listeners.get("SIGTERM")?.values().next().value?.();
|
||||
getListenerSet(listeners, "SIGTERM").values().next().value();
|
||||
expect(kill).toHaveBeenCalledWith(-4200, "SIGTERM");
|
||||
|
||||
teardown();
|
||||
expect(listeners.get("SIGINT")?.size ?? 0).toBe(0);
|
||||
expect(listeners.get("SIGTERM")?.size ?? 0).toBe(0);
|
||||
expect(listeners.get("exit")?.size ?? 0).toBe(0);
|
||||
expectListenerCount(listeners, "SIGINT", 0);
|
||||
expectListenerCount(listeners, "SIGTERM", 0);
|
||||
expectListenerCount(listeners, "exit", 0);
|
||||
});
|
||||
|
||||
it("raises process listener limits for highly parallel cleanup handlers", () => {
|
||||
@@ -134,8 +151,8 @@ describe("vitest process group helpers", () => {
|
||||
for (const teardown of teardowns) {
|
||||
teardown();
|
||||
}
|
||||
expect(listeners.get("SIGINT")?.size ?? 0).toBe(0);
|
||||
expect(listeners.get("SIGTERM")?.size ?? 0).toBe(0);
|
||||
expect(listeners.get("exit")?.size ?? 0).toBe(0);
|
||||
expectListenerCount(listeners, "SIGINT", 0);
|
||||
expectListenerCount(listeners, "SIGTERM", 0);
|
||||
expectListenerCount(listeners, "exit", 0);
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user