mirror of
https://github.com/openclaw/openclaw.git
synced 2026-08-08 19:12:22 +00:00
fix(test): reject zero RSS resource samples
This commit is contained in:
@@ -1599,13 +1599,18 @@ function assertProcessResourceCeiling(sample, { label, maxRssMiB, requireSample
|
||||
}
|
||||
return;
|
||||
}
|
||||
if (!Number.isFinite(sample.rssMiB) || sample.rssMiB <= 0) {
|
||||
throw new Error(`${label} RSS sample was invalid: ${String(sample.rssMiB)} MiB`);
|
||||
}
|
||||
const aggregateRssMiB = sample.aggregateRssMiB ?? sample.rssMiB;
|
||||
if (!Number.isFinite(aggregateRssMiB) || aggregateRssMiB <= 0) {
|
||||
throw new Error(`${label} aggregate RSS sample was invalid: ${String(aggregateRssMiB)} MiB`);
|
||||
}
|
||||
if (sample.rssMiB > maxRssMiB) {
|
||||
throw new Error(`${label} RSS exceeded ${maxRssMiB} MiB: ${sample.rssMiB} MiB`);
|
||||
}
|
||||
if ((sample.aggregateRssMiB ?? sample.rssMiB) > maxRssMiB) {
|
||||
throw new Error(
|
||||
`${label} aggregate RSS exceeded ${maxRssMiB} MiB: ${sample.aggregateRssMiB} MiB`,
|
||||
);
|
||||
if (aggregateRssMiB > maxRssMiB) {
|
||||
throw new Error(`${label} aggregate RSS exceeded ${maxRssMiB} MiB: ${aggregateRssMiB} MiB`);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -55,6 +55,11 @@ function assertSampleValue(value, raw, name, labelLocal) {
|
||||
`docker stats sample for ${labelLocal} had invalid ${name}: ${JSON.stringify(raw)}`,
|
||||
);
|
||||
}
|
||||
if (name === "MemUsage" && value <= 0) {
|
||||
throw new Error(
|
||||
`docker stats sample for ${labelLocal} had non-positive ${name}: ${JSON.stringify(raw)}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
async function scanStatsFileLines(file, onLine) {
|
||||
|
||||
@@ -89,4 +89,11 @@ describe("scripts/e2e/lib/docker-stats/assert-resource-ceiling.mjs", () => {
|
||||
expect(result.status).toBe(0);
|
||||
expect(result.stdout).toContain("samples=1");
|
||||
});
|
||||
|
||||
it("rejects zero-memory Docker stats samples as invalid proof", () => {
|
||||
const result = runAssert(writeStats('{"MemUsage":"0B / 2GiB","CPUPerc":"0.0%"}\n'));
|
||||
|
||||
expect(result.status).not.toBe(0);
|
||||
expect(result.stderr).toContain("had non-positive MemUsage");
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1188,6 +1188,15 @@ describe("kitchen-sink RPC process sampling", () => {
|
||||
expect(() => assertResourceCeiling(null)).toThrow("gateway RSS sample was not captured");
|
||||
});
|
||||
|
||||
it("fails zero-valued process RSS samples", () => {
|
||||
expect(() => assertResourceCeiling({ rssMiB: 0 })).toThrow(
|
||||
"gateway RSS sample was invalid: 0 MiB",
|
||||
);
|
||||
expect(() => assertCommandResourceCeiling({ aggregateRssMiB: 0, rssMiB: 128 })).toThrow(
|
||||
"command aggregate RSS sample was invalid: 0 MiB",
|
||||
);
|
||||
});
|
||||
|
||||
it("fails missing command samples and command RSS spikes", () => {
|
||||
expect(() => assertCommandResourceCeiling(null)).toThrow("command RSS sample was not captured");
|
||||
expect(() => assertCommandResourceCeiling({ aggregateRssMiB: 8193, rssMiB: 1024 })).toThrow(
|
||||
|
||||
Reference in New Issue
Block a user