mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-27 04:47:03 -06:00
test: cover gateway sequence reset on reconnect
This commit is contained in:
@@ -482,6 +482,42 @@ describe("GatewayClient", () => {
|
||||
client.stop();
|
||||
});
|
||||
|
||||
test("establishes a fresh event sequence baseline after an automatic reconnect", async () => {
|
||||
vi.useFakeTimers();
|
||||
const onEvent = vi.fn();
|
||||
const onGap = vi.fn();
|
||||
const { client, connections } = createSyntheticGatewayProtocol({ onEvent, onGap });
|
||||
client.start();
|
||||
const firstConnection = connections[0];
|
||||
if (!firstConnection) {
|
||||
throw new Error("synthetic protocol connection missing");
|
||||
}
|
||||
firstConnection.handlers.message(
|
||||
JSON.stringify({ type: "event", event: "board.changed", payload: {}, seq: 1 }),
|
||||
);
|
||||
|
||||
firstConnection.close(1012, "service restart");
|
||||
await vi.advanceTimersByTimeAsync(10);
|
||||
const replacementConnection = connections[1];
|
||||
if (!replacementConnection) {
|
||||
throw new Error("synthetic replacement connection missing");
|
||||
}
|
||||
replacementConnection.handlers.message(
|
||||
JSON.stringify({ type: "event", event: "board.changed", payload: {}, seq: 3 }),
|
||||
);
|
||||
|
||||
expect(onGap).not.toHaveBeenCalled();
|
||||
expect(onEvent).toHaveBeenCalledTimes(2);
|
||||
|
||||
replacementConnection.handlers.message(
|
||||
JSON.stringify({ type: "event", event: "board.changed", payload: {}, seq: 5 }),
|
||||
);
|
||||
|
||||
expect(onGap).toHaveBeenCalledExactlyOnceWith({ expected: 4, received: 5 });
|
||||
expect(onEvent).toHaveBeenCalledTimes(3);
|
||||
client.stop();
|
||||
});
|
||||
|
||||
test("restarts immediately after resetting a pending reconnect", async () => {
|
||||
vi.useFakeTimers();
|
||||
const { client, connections } = createSyntheticGatewayProtocol();
|
||||
|
||||
Reference in New Issue
Block a user