mirror of
https://github.com/farcasclaudiu/openclaw.git
synced 2026-06-28 19:01:47 +03: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 closed = new Promise<{ code: number; reason: string }>((resolve) => {
|
||||||
const client = new GatewayClient({
|
const client = new GatewayClient({
|
||||||
url: `ws://127.0.0.1:${port}`,
|
url: `ws://127.0.0.1:${port}`,
|
||||||
|
connectDelayMs: 0,
|
||||||
onClose: (code, reason) => resolve({ code, reason }),
|
onClose: (code, reason) => resolve({ code, reason }),
|
||||||
});
|
});
|
||||||
client.start();
|
client.start();
|
||||||
@@ -158,6 +159,7 @@ r1USnb+wUdA7Zoj/mQ==
|
|||||||
}, 2000);
|
}, 2000);
|
||||||
client = new GatewayClient({
|
client = new GatewayClient({
|
||||||
url: `wss://127.0.0.1:${port}`,
|
url: `wss://127.0.0.1:${port}`,
|
||||||
|
connectDelayMs: 0,
|
||||||
tlsFingerprint: "deadbeef",
|
tlsFingerprint: "deadbeef",
|
||||||
onConnectError: (err) => {
|
onConnectError: (err) => {
|
||||||
clearTimeout(timeout);
|
clearTimeout(timeout);
|
||||||
|
|||||||
@@ -40,6 +40,7 @@ type Pending = {
|
|||||||
|
|
||||||
export type GatewayClientOptions = {
|
export type GatewayClientOptions = {
|
||||||
url?: string; // ws://127.0.0.1:18789
|
url?: string; // ws://127.0.0.1:18789
|
||||||
|
connectDelayMs?: number;
|
||||||
token?: string;
|
token?: string;
|
||||||
password?: string;
|
password?: string;
|
||||||
instanceId?: string;
|
instanceId?: string;
|
||||||
@@ -338,12 +339,17 @@ export class GatewayClient {
|
|||||||
private queueConnect() {
|
private queueConnect() {
|
||||||
this.connectNonce = null;
|
this.connectNonce = null;
|
||||||
this.connectSent = false;
|
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) {
|
if (this.connectTimer) {
|
||||||
clearTimeout(this.connectTimer);
|
clearTimeout(this.connectTimer);
|
||||||
}
|
}
|
||||||
this.connectTimer = setTimeout(() => {
|
this.connectTimer = setTimeout(() => {
|
||||||
this.sendConnect();
|
this.sendConnect();
|
||||||
}, 750);
|
}, connectDelayMs);
|
||||||
}
|
}
|
||||||
|
|
||||||
private scheduleReconnect() {
|
private scheduleReconnect() {
|
||||||
|
|||||||
@@ -66,6 +66,7 @@ const connectNodeClient = async (params: {
|
|||||||
});
|
});
|
||||||
const client = new GatewayClient({
|
const client = new GatewayClient({
|
||||||
url: `ws://127.0.0.1:${params.port}`,
|
url: `ws://127.0.0.1:${params.port}`,
|
||||||
|
connectDelayMs: 0,
|
||||||
token,
|
token,
|
||||||
role: "node",
|
role: "node",
|
||||||
clientName: GATEWAY_CLIENT_NAMES.NODE_HOST,
|
clientName: GATEWAY_CLIENT_NAMES.NODE_HOST,
|
||||||
|
|||||||
@@ -253,6 +253,7 @@ const connectNode = async (
|
|||||||
|
|
||||||
const client = new GatewayClient({
|
const client = new GatewayClient({
|
||||||
url: `ws://127.0.0.1:${inst.port}`,
|
url: `ws://127.0.0.1:${inst.port}`,
|
||||||
|
connectDelayMs: 0,
|
||||||
token: inst.gatewayToken,
|
token: inst.gatewayToken,
|
||||||
clientName: GATEWAY_CLIENT_NAMES.NODE_HOST,
|
clientName: GATEWAY_CLIENT_NAMES.NODE_HOST,
|
||||||
clientDisplayName: label,
|
clientDisplayName: label,
|
||||||
@@ -327,6 +328,7 @@ const connectStatusClient = async (
|
|||||||
|
|
||||||
const client = new GatewayClient({
|
const client = new GatewayClient({
|
||||||
url: `ws://127.0.0.1:${inst.port}`,
|
url: `ws://127.0.0.1:${inst.port}`,
|
||||||
|
connectDelayMs: 0,
|
||||||
token: inst.gatewayToken,
|
token: inst.gatewayToken,
|
||||||
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
clientName: GATEWAY_CLIENT_NAMES.CLI,
|
||||||
clientDisplayName: `status-${inst.name}`,
|
clientDisplayName: `status-${inst.name}`,
|
||||||
|
|||||||
@@ -94,6 +94,7 @@ async function connectClient(params: { url: string; token: string }) {
|
|||||||
};
|
};
|
||||||
const client = new GatewayClient({
|
const client = new GatewayClient({
|
||||||
url: params.url,
|
url: params.url,
|
||||||
|
connectDelayMs: 0,
|
||||||
token: params.token,
|
token: params.token,
|
||||||
clientName: GATEWAY_CLIENT_NAMES.TEST,
|
clientName: GATEWAY_CLIENT_NAMES.TEST,
|
||||||
clientDisplayName: "vitest-timeout-fallback",
|
clientDisplayName: "vitest-timeout-fallback",
|
||||||
|
|||||||
Reference in New Issue
Block a user