mirror of
https://github.com/openclaw/openclaw.git
synced 2026-02-19 18:39:20 -05:00
perf: add zero-delay gateway client connect for tests
This commit is contained in:
@@ -69,6 +69,7 @@ describe("GatewayClient", () => {
|
||||
const closed = new Promise<{ code: number; reason: string }>((resolve) => {
|
||||
const client = new GatewayClient({
|
||||
url: `ws://127.0.0.1:${port}`,
|
||||
connectDelayMs: 0,
|
||||
onClose: (code, reason) => resolve({ code, reason }),
|
||||
});
|
||||
client.start();
|
||||
@@ -158,6 +159,7 @@ r1USnb+wUdA7Zoj/mQ==
|
||||
}, 2000);
|
||||
client = new GatewayClient({
|
||||
url: `wss://127.0.0.1:${port}`,
|
||||
connectDelayMs: 0,
|
||||
tlsFingerprint: "deadbeef",
|
||||
onConnectError: (err) => {
|
||||
clearTimeout(timeout);
|
||||
|
||||
@@ -40,6 +40,7 @@ type Pending = {
|
||||
|
||||
export type GatewayClientOptions = {
|
||||
url?: string; // ws://127.0.0.1:18789
|
||||
connectDelayMs?: number;
|
||||
token?: string;
|
||||
password?: string;
|
||||
instanceId?: string;
|
||||
@@ -338,12 +339,17 @@ export class GatewayClient {
|
||||
private queueConnect() {
|
||||
this.connectNonce = null;
|
||||
this.connectSent = false;
|
||||
const rawConnectDelayMs = this.opts.connectDelayMs;
|
||||
const connectDelayMs =
|
||||
typeof rawConnectDelayMs === "number" && Number.isFinite(rawConnectDelayMs)
|
||||
? Math.max(0, Math.min(5_000, rawConnectDelayMs))
|
||||
: 750;
|
||||
if (this.connectTimer) {
|
||||
clearTimeout(this.connectTimer);
|
||||
}
|
||||
this.connectTimer = setTimeout(() => {
|
||||
this.sendConnect();
|
||||
}, 750);
|
||||
}, connectDelayMs);
|
||||
}
|
||||
|
||||
private scheduleReconnect() {
|
||||
|
||||
@@ -66,6 +66,7 @@ const connectNodeClient = async (params: {
|
||||
});
|
||||
const client = new GatewayClient({
|
||||
url: `ws://127.0.0.1:${params.port}`,
|
||||
connectDelayMs: 0,
|
||||
token,
|
||||
role: "node",
|
||||
clientName: GATEWAY_CLIENT_NAMES.NODE_HOST,
|
||||
|
||||
@@ -253,6 +253,7 @@ const connectNode = async (
|
||||
|
||||
const client = new GatewayClient({
|
||||
url: `ws://127.0.0.1:${inst.port}`,
|
||||
connectDelayMs: 0,
|
||||
token: inst.gatewayToken,
|
||||
clientName: GATEWAY_CLIENT_NAMES.NODE_HOST,
|
||||
clientDisplayName: label,
|
||||
@@ -327,6 +328,7 @@ const connectStatusClient = async (
|
||||
|
||||
const client = new GatewayClient({
|
||||
url: `ws://127.0.0.1:${inst.port}`,
|
||||
connectDelayMs: 0,
|
||||
token: inst.gatewayToken,
|
||||
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
||||
clientDisplayName: `status-${inst.name}`,
|
||||
|
||||
@@ -94,6 +94,7 @@ async function connectClient(params: { url: string; token: string }) {
|
||||
};
|
||||
const client = new GatewayClient({
|
||||
url: params.url,
|
||||
connectDelayMs: 0,
|
||||
token: params.token,
|
||||
clientName: GATEWAY_CLIENT_NAMES.TEST,
|
||||
clientDisplayName: "vitest-timeout-fallback",
|
||||
|
||||
Reference in New Issue
Block a user