test(gateway): deflake cron finished event wait

This commit is contained in:
Peter Steinberger
2026-01-06 09:25:31 +01:00
parent 9e49c762e0
commit ed2075ce69

View File

@@ -327,7 +327,9 @@ describe("gateway server cron", () => {
: ""; : "";
expect(storePath).toContain("jobs.json"); expect(storePath).toContain("jobs.json");
const atMs = Date.now() + 80; // Avoid races: if we schedule too close to "now", the cron runner can
// finish before we start listening for the "finished" event.
const atMs = Date.now() + 1000;
const addRes = await rpcReq(ws, "cron.add", { const addRes = await rpcReq(ws, "cron.add", {
name: "auto run test", name: "auto run test",
enabled: true, enabled: true,
@@ -345,8 +347,12 @@ describe("gateway server cron", () => {
type: "event"; type: "event";
event: string; event: string;
payload?: { jobId?: string; action?: string; status?: string } | null; payload?: { jobId?: string; action?: string; status?: string } | null;
}>((resolve) => { }>((resolve, reject) => {
const timeout = setTimeout(() => resolve(null as never), 8000); const timeout = setTimeout(() => {
reject(
new Error(`timeout waiting for cron finished event: ${jobId}`),
);
}, 8000);
ws.on("message", (data) => { ws.on("message", (data) => {
const obj = JSON.parse(decodeWsData(data)); const obj = JSON.parse(decodeWsData(data));
if ( if (