mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
fix(scripts): clamp memory fd repro timers
This commit is contained in:
@@ -1,8 +1,10 @@
|
||||
// Check Memory Fd Repro tests cover check memory fd repro script behavior.
|
||||
import { EventEmitter } from "node:events";
|
||||
import fs from "node:fs";
|
||||
import { createServer, type Server } from "node:http";
|
||||
import os from "node:os";
|
||||
import path from "node:path";
|
||||
import { MAX_TIMER_TIMEOUT_MS } from "@openclaw/normalization-core/number-coercion";
|
||||
import { describe, expect, it, vi } from "vitest";
|
||||
import {
|
||||
GATEWAY_READY_OUTPUT_MAX_CHARS,
|
||||
@@ -10,6 +12,7 @@ import {
|
||||
MEMORY_SEARCH_RESPONSE_MAX_BYTES,
|
||||
classifyMemorySearchInvokeResponse,
|
||||
hasChildExited,
|
||||
invokeMemorySearch,
|
||||
parseArgs,
|
||||
readBoundedResponseText,
|
||||
readNumber,
|
||||
@@ -21,6 +24,21 @@ import {
|
||||
} from "../../scripts/check-memory-fd-repro.mjs";
|
||||
import { withEnv } from "../../src/test-utils/env.js";
|
||||
|
||||
async function listen(server: Server): Promise<number> {
|
||||
await new Promise<void>((resolve, reject) => {
|
||||
server.once("error", reject);
|
||||
server.listen(0, "127.0.0.1", () => {
|
||||
server.off("error", reject);
|
||||
resolve();
|
||||
});
|
||||
});
|
||||
const address = server.address();
|
||||
if (!address || typeof address === "string") {
|
||||
throw new Error("test server did not expose a TCP port");
|
||||
}
|
||||
return address.port;
|
||||
}
|
||||
|
||||
describe("check-memory-fd-repro", () => {
|
||||
it("parses file, fd, and timing limits as strict integers", () => {
|
||||
expect(readNumber("0", "limit")).toBe(0);
|
||||
@@ -40,13 +58,17 @@ describe("check-memory-fd-repro", () => {
|
||||
OPENCLAW_MEMORY_FD_REPRO_FILES: "17",
|
||||
OPENCLAW_MEMORY_FD_REPRO_MAX_WORKSPACE_REG_FDS: "0",
|
||||
OPENCLAW_MEMORY_FD_REPRO_SAMPLE_DELAY_MS: "0",
|
||||
OPENCLAW_MEMORY_FD_REPRO_SETTLE_DELAY_MS: String(MAX_TIMER_TIMEOUT_MS + 1),
|
||||
OPENCLAW_MEMORY_FD_REPRO_TIMEOUT_MS: String(MAX_TIMER_TIMEOUT_MS + 1),
|
||||
},
|
||||
() => parseArgs([]),
|
||||
),
|
||||
).toMatchObject({
|
||||
fileCount: 17,
|
||||
invokeTimeoutMs: MAX_TIMER_TIMEOUT_MS,
|
||||
maxWorkspaceRegFds: 0,
|
||||
sampleDelayMs: 0,
|
||||
settleDelayMs: MAX_TIMER_TIMEOUT_MS,
|
||||
});
|
||||
|
||||
expect(() =>
|
||||
@@ -109,6 +131,37 @@ describe("check-memory-fd-repro", () => {
|
||||
});
|
||||
});
|
||||
|
||||
it("clamps oversized memory_search invoke timers before scheduling", async () => {
|
||||
const server = createServer((_request, response) => {
|
||||
setTimeout(() => {
|
||||
response.writeHead(200, { "content-type": "application/json" }).end(
|
||||
JSON.stringify({
|
||||
ok: true,
|
||||
result: {
|
||||
content: [{ type: "text", text: JSON.stringify({ results: [] }) }],
|
||||
},
|
||||
}),
|
||||
);
|
||||
}, 25);
|
||||
});
|
||||
const port = await listen(server);
|
||||
try {
|
||||
await expect(
|
||||
invokeMemorySearch({
|
||||
port,
|
||||
token: "test-token",
|
||||
timeoutMs: MAX_TIMER_TIMEOUT_MS + 1,
|
||||
}),
|
||||
).resolves.toMatchObject({
|
||||
gatewayOk: true,
|
||||
ok: true,
|
||||
resultCount: 0,
|
||||
});
|
||||
} finally {
|
||||
await new Promise<void>((resolve) => server.close(() => resolve()));
|
||||
}
|
||||
});
|
||||
|
||||
it("uses a fast matching probe query instead of a no-hit stress query", () => {
|
||||
expect(MEMORY_SEARCH_PROBE_QUERY).toBe("Top-level memory file");
|
||||
expect(MEMORY_SEARCH_PROBE_QUERY).not.toContain("nomatch");
|
||||
|
||||
Reference in New Issue
Block a user