Cover stale websocket message isolation after renderer reconnect
Co-authored-by: Theo Browne <[email protected]>
This commit is contained in:
1 parent
5323a138c4
commit
bb9804cf70
1 file changed
+55
@@ -973,6 +973,61 @@ describe("wsNativeApi", () => {
|
||||
await expect(secondRequest).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it("ignores stale message events from prior sockets after reconnect", async () => {
|
||||
setWindowSearch("?ws=ws%3A%2F%2F127.0.0.1%3A4477");
|
||||
const { getOrCreateWsNativeApi } = await import("./wsNativeApi");
|
||||
const api = getOrCreateWsNativeApi();
|
||||
|
||||
const firstRequest = api.todos.list();
|
||||
const firstSocket = await waitForSocket();
|
||||
await waitForCondition(() => firstSocket.sentMessages.length > 0);
|
||||
const firstEnvelope = JSON.parse(firstSocket.sentMessages[0] ?? "{}") as {
|
||||
id: string;
|
||||
};
|
||||
firstSocket.emitMessage(
|
||||
JSON.stringify({
|
||||
type: "response",
|
||||
id: firstEnvelope.id,
|
||||
ok: true,
|
||||
result: [],
|
||||
}),
|
||||
);
|
||||
await expect(firstRequest).resolves.toEqual([]);
|
||||
|
||||
firstSocket.closeWith({
|
||||
code: WS_CLOSE_CODES.unauthorized,
|
||||
reason: WS_CLOSE_REASONS.unauthorized,
|
||||
});
|
||||
|
||||
const secondRequest = api.todos.list();
|
||||
await waitForCondition(() => MockWebSocket.instances.length >= 2);
|
||||
const secondSocket = MockWebSocket.instances[1];
|
||||
await waitForCondition(() => (secondSocket?.sentMessages.length ?? 0) > 0);
|
||||
const secondEnvelope = JSON.parse(secondSocket?.sentMessages[0] ?? "{}") as {
|
||||
id: string;
|
||||
};
|
||||
|
||||
firstSocket.emitMessage(
|
||||
JSON.stringify({
|
||||
type: "response",
|
||||
id: secondEnvelope.id,
|
||||
ok: true,
|
||||
result: ["stale-result"],
|
||||
}),
|
||||
);
|
||||
|
||||
secondSocket?.emitMessage(
|
||||
JSON.stringify({
|
||||
type: "response",
|
||||
id: secondEnvelope.id,
|
||||
ok: true,
|
||||
result: [],
|
||||
}),
|
||||
);
|
||||
|
||||
await expect(secondRequest).resolves.toEqual([]);
|
||||
});
|
||||
|
||||
it("rejects requests when runtime does not respond before timeout", async () => {
|
||||
vi.useFakeTimers();
|
||||
try {
|
||||
|
||||
Reference in new issue
Block a user