36 lines
3.1 KiB
JavaScript
36 lines
3.1 KiB
JavaScript
import assert from "node:assert/strict";
|
|
import crypto from "node:crypto";
|
|
import fs from "node:fs/promises";
|
|
import os from "node:os";
|
|
import path from "node:path";
|
|
import { fileURLToPath } from "node:url";
|
|
import { createServerJobFaultReceipt } from "./server-job-fault.mjs";
|
|
import { startServerJobProcess } from "./server-job-process.mjs";
|
|
|
|
const root = path.resolve(path.dirname(fileURLToPath(import.meta.url)), "../..");
|
|
const reportPath = path.join(root, "tests/golden/M13-04H/server-job-fault-report.json");
|
|
const manifestPath = path.join(root, "tests/golden/M13-04H/manifest.json");
|
|
const hashFile = async (file) => crypto.createHash("sha256").update(await fs.readFile(file)).digest("hex");
|
|
const failed = startServerJobProcess(process.execPath, ["-e", "process.exit(7)"], { cwd: root });
|
|
const failedResult = await failed.completion;
|
|
const signalled = startServerJobProcess(process.execPath, ["-e", "process.kill(process.pid, 'SIGTERM')"], { cwd: root });
|
|
const signalledResult = await signalled.completion;
|
|
const receipts = {
|
|
timeout: createServerJobFaultReceipt({ baseRevision: 11, currentRevision: 11, timedOut: true }),
|
|
oom: createServerJobFaultReceipt({ baseRevision: 11, currentRevision: 11, memoryBytes: 513, memoryLimitBytes: 512 }),
|
|
signal: createServerJobFaultReceipt({ baseRevision: 11, currentRevision: 11, signal: signalledResult.result.signal }),
|
|
exit: createServerJobFaultReceipt({ baseRevision: 11, currentRevision: 11, code: failedResult.result.code }),
|
|
};
|
|
assert.equal(receipts.timeout.code, "SERVER_JOB_TIMEOUT");
|
|
assert.equal(receipts.oom.code, "SERVER_JOB_OOM");
|
|
assert.equal(receipts.signal.code, "SERVER_JOB_SIGNAL");
|
|
assert.equal(receipts.exit.code, "SERVER_JOB_EXIT_FAILED");
|
|
for (const receipt of Object.values(receipts)) { assert.equal(receipt.publish, false); assert.equal(receipt.revisionPreserved, true); assert.equal(receipt.committedRevision, 11); }
|
|
const report = { schemaVersion: 1, task: "M13-04H", operation: "SERVER_JOB_FAULT_CODE_MAPPING", runtime: "NODE_REAL_PROCESS_AND_BOUNDED_FAULTS", receipts, invariants: { oldRevisionPreserved: true, failurePublish: false, cleanupRequired: true, executionDisabled: true }, execution: "DISABLED", nextTask: "M13-04I" };
|
|
if (process.env.UPDATE_M13_04H_REPORT === "1") { await fs.mkdir(path.dirname(reportPath), { recursive: true }); await fs.writeFile(reportPath, `${JSON.stringify(report, null, 2)}\n`); }
|
|
assert.deepEqual(JSON.parse(await fs.readFile(reportPath, "utf8")), report);
|
|
const manifest = JSON.parse(await fs.readFile(manifestPath, "utf8"));
|
|
assert.deepEqual({ schemaVersion: manifest.schemaVersion, task: manifest.task, parentTask: manifest.parentTask, nextTask: manifest.nextTask }, { schemaVersion: 1, task: "M13-04H", parentTask: "M13-04G", nextTask: "M13-04I" });
|
|
for (const artifact of Object.values(manifest.artifacts)) assert.equal(await hashFile(path.join(root, artifact.path)), artifact.sha256, `artifact hash mismatch ${artifact.path}`);
|
|
process.stdout.write(`server-job-faults-ok timeout=SERVER_JOB_TIMEOUT oom=SERVER_JOB_OOM signal=SERVER_JOB_SIGNAL exit=SERVER_JOB_EXIT_FAILED revisionPreserved=1 publish=0 execution=DISABLED next=${manifest.nextTask}\n`);
|