44 lines
2.5 KiB
TypeScript
44 lines
2.5 KiB
TypeScript
import { expect, mock, test } from "bun:test";
|
|
import { watchSingleJob } from "./single-job.js";
|
|
import { watchWorkflowPipeline } from "./pipeline-watcher.js";
|
|
function client(status = "RUNNING") {
|
|
return { get: mock(async (path: string) => Response.json({ data: path.includes("/execution") ? [] : { id: "job", pipelineId: "wf", status } })) } as any;
|
|
}
|
|
test("a running job times out without a completion event or false success report", async () => {
|
|
const report = await watchWorkflowPipeline(client(), "wf", { jobId: "job", timeoutMs: 5 });
|
|
expect(report.timedOut).toBe(true);
|
|
expect(report.jobs[0].status).toBe("RUNNING");
|
|
expect(report.jobs[0].events.map(e => e.type)).toContain("timeout");
|
|
expect(report.jobs[0].events.some(e => e.type === "job_completed")).toBe(false);
|
|
});
|
|
test("once snapshots are not timeouts and completed jobs still emit completion", async () => {
|
|
const snapshot = await watchSingleJob(client(), "job", { once: true });
|
|
expect(snapshot.timedOut).toBe(false);
|
|
expect(snapshot.events.some(e => e.type === "job_completed")).toBe(false);
|
|
const completed = await watchSingleJob(client("COMPLETED"), "job", { timeoutMs: 100 });
|
|
expect(completed.timedOut).toBe(false);
|
|
expect(completed.events.at(-1)?.type).toBe("job_completed");
|
|
});
|
|
test("cancellation is distinct from timeout and completion", async () => {
|
|
const controller = new AbortController(); controller.abort();
|
|
const c = client();
|
|
const result = await watchSingleJob(c, "job", { signal: controller.signal });
|
|
expect(result.cancelled).toBe(true); expect(result.timedOut).toBe(false);
|
|
expect(result.events.map(e => e.type)).toEqual(["cancelled"]);
|
|
expect(c.get).not.toHaveBeenCalled();
|
|
});
|
|
|
|
test("latest-job snapshots propagate cancellation from the selected job", async () => {
|
|
const controller = new AbortController();
|
|
const c = { get: async (path: string) => {
|
|
if (path.endsWith("/running")) return Response.json({ data: [{ id: "job", pipelineId: "wf" }] });
|
|
if (path.includes("/pipelines/")) return Response.json({ data: { id: "wf", tasks: [] } });
|
|
if (path.includes("/execution")) return Response.json({ data: [] });
|
|
controller.abort();
|
|
return Response.json({ data: { id: "job", pipelineId: "wf", status: "RUNNING" } });
|
|
} } as any;
|
|
const report = await watchWorkflowPipeline(c, "wf", { once: true, signal: controller.signal });
|
|
expect(report.cancelled).toBe(true); expect(report.timedOut).toBe(false);
|
|
expect(report.jobs[0].events.some(e => e.type === "job_completed")).toBe(false);
|
|
});
|