mirror of https://github.com/openclaw/openclaw.git
test: dedupe acp startup test harness
This commit is contained in:
parent
1301462a1b
commit
d9fb1e0e45
|
|
@ -129,6 +129,22 @@ describe("serveAcpGateway startup", () => {
|
||||||
return { signalHandlers, onceSpy };
|
return { signalHandlers, onceSpy };
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function emitHelloAndWaitForAgentSideConnection() {
|
||||||
|
const gateway = getMockGateway();
|
||||||
|
gateway.emitHello();
|
||||||
|
await vi.waitFor(() => {
|
||||||
|
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
async function stopServeWithSigint(
|
||||||
|
signalHandlers: Map<NodeJS.Signals, () => void>,
|
||||||
|
servePromise: Promise<void>,
|
||||||
|
) {
|
||||||
|
signalHandlers.get("SIGINT")?.();
|
||||||
|
await servePromise;
|
||||||
|
}
|
||||||
|
|
||||||
beforeAll(async () => {
|
beforeAll(async () => {
|
||||||
({ serveAcpGateway } = await import("./server.js"));
|
({ serveAcpGateway } = await import("./server.js"));
|
||||||
});
|
});
|
||||||
|
|
@ -153,14 +169,8 @@ describe("serveAcpGateway startup", () => {
|
||||||
await Promise.resolve();
|
await Promise.resolve();
|
||||||
|
|
||||||
expect(mockState.agentSideConnectionCtor).not.toHaveBeenCalled();
|
expect(mockState.agentSideConnectionCtor).not.toHaveBeenCalled();
|
||||||
const gateway = getMockGateway();
|
await emitHelloAndWaitForAgentSideConnection();
|
||||||
gateway.emitHello();
|
await stopServeWithSigint(signalHandlers, servePromise);
|
||||||
await vi.waitFor(() => {
|
|
||||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
|
|
||||||
signalHandlers.get("SIGINT")?.();
|
|
||||||
await servePromise;
|
|
||||||
} finally {
|
} finally {
|
||||||
onceSpy.mockRestore();
|
onceSpy.mockRestore();
|
||||||
}
|
}
|
||||||
|
|
@ -207,13 +217,8 @@ describe("serveAcpGateway startup", () => {
|
||||||
password: "resolved-secret-password", // pragma: allowlist secret
|
password: "resolved-secret-password", // pragma: allowlist secret
|
||||||
});
|
});
|
||||||
|
|
||||||
const gateway = getMockGateway();
|
await emitHelloAndWaitForAgentSideConnection();
|
||||||
gateway.emitHello();
|
await stopServeWithSigint(signalHandlers, servePromise);
|
||||||
await vi.waitFor(() => {
|
|
||||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
signalHandlers.get("SIGINT")?.();
|
|
||||||
await servePromise;
|
|
||||||
} finally {
|
} finally {
|
||||||
onceSpy.mockRestore();
|
onceSpy.mockRestore();
|
||||||
}
|
}
|
||||||
|
|
@ -236,13 +241,8 @@ describe("serveAcpGateway startup", () => {
|
||||||
}),
|
}),
|
||||||
);
|
);
|
||||||
|
|
||||||
const gateway = getMockGateway();
|
await emitHelloAndWaitForAgentSideConnection();
|
||||||
gateway.emitHello();
|
await stopServeWithSigint(signalHandlers, servePromise);
|
||||||
await vi.waitFor(() => {
|
|
||||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
|
||||||
});
|
|
||||||
signalHandlers.get("SIGINT")?.();
|
|
||||||
await servePromise;
|
|
||||||
} finally {
|
} finally {
|
||||||
onceSpy.mockRestore();
|
onceSpy.mockRestore();
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue