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 };
|
||||
}
|
||||
|
||||
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 () => {
|
||||
({ serveAcpGateway } = await import("./server.js"));
|
||||
});
|
||||
|
|
@ -153,14 +169,8 @@ describe("serveAcpGateway startup", () => {
|
|||
await Promise.resolve();
|
||||
|
||||
expect(mockState.agentSideConnectionCtor).not.toHaveBeenCalled();
|
||||
const gateway = getMockGateway();
|
||||
gateway.emitHello();
|
||||
await vi.waitFor(() => {
|
||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
signalHandlers.get("SIGINT")?.();
|
||||
await servePromise;
|
||||
await emitHelloAndWaitForAgentSideConnection();
|
||||
await stopServeWithSigint(signalHandlers, servePromise);
|
||||
} finally {
|
||||
onceSpy.mockRestore();
|
||||
}
|
||||
|
|
@ -207,13 +217,8 @@ describe("serveAcpGateway startup", () => {
|
|||
password: "resolved-secret-password", // pragma: allowlist secret
|
||||
});
|
||||
|
||||
const gateway = getMockGateway();
|
||||
gateway.emitHello();
|
||||
await vi.waitFor(() => {
|
||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
signalHandlers.get("SIGINT")?.();
|
||||
await servePromise;
|
||||
await emitHelloAndWaitForAgentSideConnection();
|
||||
await stopServeWithSigint(signalHandlers, servePromise);
|
||||
} finally {
|
||||
onceSpy.mockRestore();
|
||||
}
|
||||
|
|
@ -236,13 +241,8 @@ describe("serveAcpGateway startup", () => {
|
|||
}),
|
||||
);
|
||||
|
||||
const gateway = getMockGateway();
|
||||
gateway.emitHello();
|
||||
await vi.waitFor(() => {
|
||||
expect(mockState.agentSideConnectionCtor).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
signalHandlers.get("SIGINT")?.();
|
||||
await servePromise;
|
||||
await emitHelloAndWaitForAgentSideConnection();
|
||||
await stopServeWithSigint(signalHandlers, servePromise);
|
||||
} finally {
|
||||
onceSpy.mockRestore();
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue