Files
continuum-backend/tests/late_failure.test.ts
T
octoturge b431ee4030 Apply job outcomes a gateway kept while the cloud was away
A job_event from a gateway moves a job that is still in flight (uploading,
printing, paused) to printing, completed or failed, and is acknowledged
whether or not it changed anything so the gateway stops sending it. A job
the cloud has cancelled, completed or put back in the queue is left alone,
and a gateway can only touch jobs of its own farm. If the database is
unreachable it is not acknowledged, so it is sent again.

scripts/e2e-vendors.sh gains a phase that takes the backend away for the
whole of a fake print and checks the job completes on reconnect from the
proxy's kept record.
2026-10-30 08:05:05 +00:00

52 lines
2.1 KiB
TypeScript

import { describe, expect, test } from "bun:test";
import { rememberStart, takeStart } from "../src/dispatch/late_failure";
describe("late start failures", () => {
test("a remembered start is returned once, then forgotten", () => {
rememberStart("c1", "job-1");
expect(takeStart("c1")).toBe("job-1");
expect(takeStart("c1")).toBeUndefined();
});
test("a command nobody started is unknown", () => {
expect(takeStart("never-sent")).toBeUndefined();
});
test("an hour-old start is dropped rather than failing a job long since resolved", () => {
const longAgo = Date.now() - 2 * 60 * 60 * 1000;
rememberStart("old", "job-old", longAgo);
rememberStart("new", "job-new");
expect(takeStart("old")).toBeUndefined();
expect(takeStart("new")).toBe("job-new");
});
test("the table is bounded", () => {
for (let i = 0; i < 1500; i++) rememberStart(`bulk-${i}`, `job-${i}`);
expect(takeStart("bulk-0")).toBeUndefined();
expect(takeStart("bulk-1499")).toBe("job-1499");
});
});
import { jobStatusFromGatewayEvent } from "../src/dispatch/job_status";
describe("jobStatusFromGatewayEvent", () => {
test("a finish is believed for any job still in flight, even one never seen printing", () => {
for (const current of ["uploading", "printing", "paused"]) {
expect(jobStatusFromGatewayEvent(current, "finished")).toBe("completed");
expect(jobStatusFromGatewayEvent(current, "failed")).toBe("failed");
}
});
test("started only promotes a job that was still uploading", () => {
expect(jobStatusFromGatewayEvent("uploading", "started")).toBe("printing");
expect(jobStatusFromGatewayEvent("printing", "started")).toBeUndefined();
expect(jobStatusFromGatewayEvent("paused", "started")).toBeUndefined();
});
test("a job the cloud has already settled or taken back is left alone", () => {
for (const current of ["queued", "completed", "failed", "cancelled"]) {
for (const event of ["started", "finished", "failed"] as const) {
expect(jobStatusFromGatewayEvent(current, event)).toBeUndefined();
}
}
});
});