diff --git a/src/gateway/client.e2e.test.ts b/src/gateway/client.e2e.test.ts index 2b7978b19da..4a4f15f815e 100644 --- a/src/gateway/client.e2e.test.ts +++ b/src/gateway/client.e2e.test.ts @@ -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); diff --git a/src/gateway/client.ts b/src/gateway/client.ts index 5a492c8c351..d19824c6abf 100644 --- a/src/gateway/client.ts +++ b/src/gateway/client.ts @@ -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() { diff --git a/src/gateway/server.roles-allowlist-update.e2e.test.ts b/src/gateway/server.roles-allowlist-update.e2e.test.ts index 873c8d65e2d..9fa8b3f9e7d 100644 --- a/src/gateway/server.roles-allowlist-update.e2e.test.ts +++ b/src/gateway/server.roles-allowlist-update.e2e.test.ts @@ -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, diff --git a/test/gateway.multi.e2e.test.ts b/test/gateway.multi.e2e.test.ts index 7f98d779bb3..caafa416f6d 100644 --- a/test/gateway.multi.e2e.test.ts +++ b/test/gateway.multi.e2e.test.ts @@ -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}`, diff --git a/test/provider-timeout.e2e.test.ts b/test/provider-timeout.e2e.test.ts index 82779cb4983..6b547cfc6f8 100644 --- a/test/provider-timeout.e2e.test.ts +++ b/test/provider-timeout.e2e.test.ts @@ -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",