zed/script/randomized-test-ci

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

71 lines
1.6 KiB
Text
Raw Normal View History

#!/usr/bin/env node --redirect-warnings=/dev/null
2024-01-23 17:34:43 +00:00
const fs = require("fs");
const { randomBytes } = require("crypto");
const { execFileSync } = require("child_process");
const {
minimizeTestPlan,
buildTests,
runTests,
} = require("./randomized-test-minimize");
2024-01-23 17:34:43 +00:00
const { ZED_SERVER_URL } = process.env;
if (!ZED_SERVER_URL) throw new Error("Missing env var `ZED_SERVER_URL`");
2024-01-23 17:34:43 +00:00
main();
async function main() {
2024-01-23 17:34:43 +00:00
buildTests();
const seed = randomU64();
2024-01-23 17:34:43 +00:00
const commit = execFileSync("git", ["rev-parse", "HEAD"], {
encoding: "utf8",
}).trim();
2024-01-23 17:34:43 +00:00
console.log("commit:", commit);
console.log("starting seed:", seed);
2024-01-23 17:34:43 +00:00
const planPath = "target/test-plan.json";
const minPlanPath = "target/test-plan.min.json";
const failingSeed = runTests({
SEED: seed,
SAVE_PLAN: planPath,
ITERATIONS: 50000,
OPERATIONS: 200,
2024-01-23 17:34:43 +00:00
});
if (!failingSeed) {
2024-01-23 17:34:43 +00:00
console.log("tests passed");
return;
}
2024-01-23 17:34:43 +00:00
console.log("found failure at seed", failingSeed);
const minimizedSeed = minimizeTestPlan(planPath, minPlanPath);
const minimizedPlan = fs.readFileSync(minPlanPath, "utf8");
2024-01-23 17:34:43 +00:00
console.log("minimized plan:\n", minimizedPlan);
2024-01-23 17:34:43 +00:00
const url = `${ZED_SERVER_URL}/api/randomized_test_failure`;
const body = {
seed: minimizedSeed,
plan: JSON.parse(minimizedPlan),
commit: commit,
2024-01-23 17:34:43 +00:00
};
await fetch(url, {
2024-01-23 17:34:43 +00:00
method: "POST",
headers: { "Content-Type": "application/json" },
body: JSON.stringify(body),
});
2024-01-23 17:34:43 +00:00
process.exit(1);
}
function randomU64() {
2024-01-23 17:34:43 +00:00
const bytes = randomBytes(8);
const hexString = bytes.reduce(
(string, byte) => string + byte.toString(16),
"",
);
return BigInt("0x" + hexString).toString(10);
}