mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-11 03:04:32 +00:00
test(gateway): dedupe canvas ws connect assertions
This commit is contained in:
@@ -59,6 +59,23 @@ async function expectWsRejected(
|
|||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
async function expectWsConnected(url: string): Promise<void> {
|
||||||
|
await new Promise<void>((resolve, reject) => {
|
||||||
|
const ws = new WebSocket(url);
|
||||||
|
const timer = setTimeout(() => reject(new Error("timeout")), WS_CONNECT_TIMEOUT_MS);
|
||||||
|
ws.once("open", () => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
ws.terminate();
|
||||||
|
resolve();
|
||||||
|
});
|
||||||
|
ws.once("unexpected-response", (_req, res) => {
|
||||||
|
clearTimeout(timer);
|
||||||
|
reject(new Error(`unexpected response ${res.statusCode}`));
|
||||||
|
});
|
||||||
|
ws.once("error", reject);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
function makeWsClient(params: {
|
function makeWsClient(params: {
|
||||||
connId: string;
|
connId: string;
|
||||||
clientIp: string;
|
clientIp: string;
|
||||||
@@ -243,20 +260,7 @@ describe("gateway canvas host auth", () => {
|
|||||||
);
|
);
|
||||||
expect(scopedA2ui.status).toBe(200);
|
expect(scopedA2ui.status).toBe(200);
|
||||||
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
await expectWsConnected(`ws://${host}:${listener.port}${activeWsPath}`);
|
||||||
const ws = new WebSocket(`ws://${host}:${listener.port}${activeWsPath}`);
|
|
||||||
const timer = setTimeout(() => reject(new Error("timeout")), WS_CONNECT_TIMEOUT_MS);
|
|
||||||
ws.once("open", () => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
ws.terminate();
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
ws.once("unexpected-response", (_req, res) => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
reject(new Error(`unexpected response ${res.statusCode}`));
|
|
||||||
});
|
|
||||||
ws.once("error", reject);
|
|
||||||
});
|
|
||||||
|
|
||||||
clients.delete(activeNodeClient);
|
clients.delete(activeNodeClient);
|
||||||
|
|
||||||
@@ -361,20 +365,7 @@ describe("gateway canvas host auth", () => {
|
|||||||
const scopedCanvas = await fetch(`http://[::1]:${listener.port}${canvasPath}`);
|
const scopedCanvas = await fetch(`http://[::1]:${listener.port}${canvasPath}`);
|
||||||
expect(scopedCanvas.status).toBe(200);
|
expect(scopedCanvas.status).toBe(200);
|
||||||
|
|
||||||
await new Promise<void>((resolve, reject) => {
|
await expectWsConnected(`ws://[::1]:${listener.port}${wsPath}`);
|
||||||
const ws = new WebSocket(`ws://[::1]:${listener.port}${wsPath}`);
|
|
||||||
const timer = setTimeout(() => reject(new Error("timeout")), WS_CONNECT_TIMEOUT_MS);
|
|
||||||
ws.once("open", () => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
ws.terminate();
|
|
||||||
resolve();
|
|
||||||
});
|
|
||||||
ws.once("unexpected-response", (_req, res) => {
|
|
||||||
clearTimeout(timer);
|
|
||||||
reject(new Error(`unexpected response ${res.statusCode}`));
|
|
||||||
});
|
|
||||||
ws.once("error", reject);
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
} catch (err) {
|
} catch (err) {
|
||||||
|
|||||||
Reference in New Issue
Block a user