perf: reduce test/runtime overhead in plugin runtime and e2e harness

This commit is contained in:
Peter Steinberger
2026-02-13 18:24:14 +00:00
parent 3cbcba10cf
commit 39e6e4cd2c
4 changed files with 111 additions and 21 deletions

View File

@@ -231,7 +231,7 @@ const runCliJson = async (args: string[], env: NodeJS.ProcessEnv): Promise<unkno
}
};
const postJson = async (url: string, body: unknown) => {
const postJson = async (url: string, body: unknown, headers?: Record<string, string>) => {
const payload = JSON.stringify(body);
const parsed = new URL(url);
return await new Promise<{ status: number; json: unknown }>((resolve, reject) => {
@@ -244,6 +244,7 @@ const postJson = async (url: string, body: unknown) => {
headers: {
"Content-Type": "application/json",
"Content-Length": Buffer.byteLength(payload),
...headers,
},
},
(res) => {
@@ -440,14 +441,22 @@ describe("gateway multi-instance e2e", () => {
expect(healthB.ok).toBe(true);
const [hookResA, hookResB] = await Promise.all([
postJson(`http://127.0.0.1:${gwA.port}/hooks/wake?token=${gwA.hookToken}`, {
text: "wake a",
mode: "now",
}),
postJson(`http://127.0.0.1:${gwB.port}/hooks/wake?token=${gwB.hookToken}`, {
text: "wake b",
mode: "now",
}),
postJson(
`http://127.0.0.1:${gwA.port}/hooks/wake`,
{
text: "wake a",
mode: "now",
},
{ "x-openclaw-token": gwA.hookToken },
),
postJson(
`http://127.0.0.1:${gwB.port}/hooks/wake`,
{
text: "wake b",
mode: "now",
},
{ "x-openclaw-token": gwB.hookToken },
),
]);
expect(hookResA.status).toBe(200);
expect((hookResA.json as { ok?: boolean } | undefined)?.ok).toBe(true);

View File

@@ -2,6 +2,12 @@ import { afterAll, afterEach, beforeEach, vi } from "vitest";
// Ensure Vitest environment is properly set
process.env.VITEST = "true";
// Vitest vm forks can load transitive lockfile helpers many times per worker.
// Raise listener budget to avoid noisy MaxListeners warnings and warning-stack overhead.
const TEST_PROCESS_MAX_LISTENERS = 128;
if (process.getMaxListeners() > 0 && process.getMaxListeners() < TEST_PROCESS_MAX_LISTENERS) {
process.setMaxListeners(TEST_PROCESS_MAX_LISTENERS);
}
import type {
ChannelId,