75 lines
2.4 KiB
JavaScript
75 lines
2.4 KiB
JavaScript
import test from "node:test";
|
|
import assert from "node:assert/strict";
|
|
import { spawn } from "node:child_process";
|
|
import { mkdtemp, readFile, rm } from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
|
|
const repoRoot = path.resolve(import.meta.dirname, "..");
|
|
|
|
function runStress(args) {
|
|
return new Promise((resolve) => {
|
|
const child = spawn(process.execPath, ["scripts/stress-remote-control.mjs", ...args], {
|
|
cwd: repoRoot,
|
|
env: process.env,
|
|
stdio: ["ignore", "pipe", "pipe"],
|
|
});
|
|
let stdout = "";
|
|
let stderr = "";
|
|
child.stdout.setEncoding("utf8");
|
|
child.stderr.setEncoding("utf8");
|
|
child.stdout.on("data", (chunk) => {
|
|
stdout += chunk;
|
|
});
|
|
child.stderr.on("data", (chunk) => {
|
|
stderr += chunk;
|
|
});
|
|
child.on("close", (status) => {
|
|
resolve({ status, stdout, stderr });
|
|
});
|
|
});
|
|
}
|
|
|
|
test("remote control stress script writes a reusable JSON report", async () => {
|
|
const tempDir = await mkdtemp(path.join(os.tmpdir(), "boss-stress-report-test-"));
|
|
const reportPath = path.join(tempDir, "remote-control-stress.json");
|
|
try {
|
|
const result = await runStress([
|
|
"--chain-tasks=4",
|
|
"--runtime-tasks=6",
|
|
"--runtime-concurrency=3",
|
|
"--timeout-ms=20000",
|
|
`--report-json=${reportPath}`,
|
|
]);
|
|
|
|
assert.equal(result.status, 0, result.stderr || result.stdout);
|
|
const report = JSON.parse(await readFile(reportPath, "utf8"));
|
|
assert.equal(report.ok, true);
|
|
assert.equal(report.options.chainTasks, 4);
|
|
assert.equal(report.options.runtimeTasks, 6);
|
|
assert.match(report.startedAt, /^\d{4}-\d{2}-\d{2}T/);
|
|
assert.match(report.finishedAt, /^\d{4}-\d{2}-\d{2}T/);
|
|
assert.ok(report.durationMs >= 0);
|
|
assert.equal(report.summaries.length, 2);
|
|
assert.equal(report.summaries[0].missing, 0);
|
|
assert.equal(report.summaries[1].failed, 0);
|
|
} finally {
|
|
await rm(tempDir, { recursive: true, force: true });
|
|
}
|
|
});
|
|
|
|
test("remote control stress script fails when latency budget is exceeded", async () => {
|
|
const result = await runStress([
|
|
"--chain-tasks=4",
|
|
"--skip-runtime",
|
|
"--timeout-ms=20000",
|
|
"--max-chain-p95-ms=1",
|
|
]);
|
|
|
|
assert.notEqual(result.status, 0);
|
|
const report = JSON.parse(result.stdout);
|
|
assert.equal(report.ok, false);
|
|
assert.equal(report.thresholdFailures.length, 1);
|
|
assert.equal(report.thresholdFailures[0].name, "chain_p95_latency");
|
|
});
|