fix(test): reject zero RSS resource samples

This commit is contained in:
Vincent Koc
2026-06-06 20:47:51 +02:00
parent bf5e0e9f10
commit c4b64de017
4 changed files with 30 additions and 4 deletions

View File

@@ -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`);
}
}

View File

@@ -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) {

View File

@@ -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");
});
});

View File

@@ -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(