test: follow deferred cron startup catch-up

This commit is contained in:
Peter Steinberger
2026-04-29 09:29:12 +01:00
parent dc810437e7
commit 2a64f1a2de
2 changed files with 25 additions and 25 deletions

View File

@@ -214,7 +214,7 @@ describe("CronService read ops while job is running", () => {
}
});
it("keeps list and status responsive during startup catch-up runs", async () => {
it("keeps list and status responsive after startup defers catch-up runs", async () => {
const store = await makeStorePath();
const enqueueSystemEvent = vi.fn();
const requestHeartbeatNow = vi.fn();
@@ -249,12 +249,12 @@ describe("CronService read ops while job is running", () => {
enqueueSystemEvent,
requestHeartbeatNow,
runIsolatedAgentJob: isolatedRun.runIsolatedAgentJob,
startupDeferredMissedAgentJobDelayMs: 120_000,
});
try {
const startPromise = cron.start();
await isolatedRun.runStarted;
expect(isolatedRun.runIsolatedAgentJob).toHaveBeenCalledTimes(1);
await cron.start();
expect(isolatedRun.runIsolatedAgentJob).not.toHaveBeenCalled();
await expect(
withTimeout(cron.list({ includeDisabled: true }), 300, "cron.list during startup"),
@@ -263,12 +263,10 @@ describe("CronService read ops while job is running", () => {
expect.objectContaining({ enabled: true, storePath: store.storePath }),
);
isolatedRun.completeRun({ status: "ok", summary: "done" });
await startPromise;
const jobs = await cron.list({ includeDisabled: true });
expect(jobs[0]?.state.lastStatus).toBe("ok");
expect(jobs[0]?.state.lastStatus).toBeUndefined();
expect(jobs[0]?.state.runningAtMs).toBeUndefined();
expect(jobs[0]?.state.nextRunAtMs).toBe(nowMs + 120_000);
} finally {
cron.stop();
await store.cleanup();

View File

@@ -7,6 +7,7 @@ import { loadCronStore } from "../store.js";
import type { CronJob } from "../types.js";
import { run, start, stop, update } from "./ops.js";
import { createCronServiceState } from "./state.js";
import { runMissedJobs } from "./timer.js";
const { logger, makeStorePath } = setupCronServiceSuite({
prefix: "cron-service-ops-seam",
@@ -326,25 +327,26 @@ describe("cron service ops seam coverage", () => {
const now = Date.parse("2026-03-23T12:00:00.000Z");
const restoreStateDir = withStateDirForStorePath(storePath);
await writeCronStoreSnapshot({
storePath,
jobs: [createMissedIsolatedJob(now)],
});
try {
await writeCronStoreSnapshot({
storePath,
jobs: [createMissedIsolatedJob(now)],
});
const state = createTimedOutIsolatedCronState({
storePath,
now,
});
const state = createTimedOutIsolatedCronState({
storePath,
now,
});
await start(state);
await runMissedJobs(state);
expect(findTaskByRunId(`cron:startup-timeout:${now}`)).toMatchObject({
runtime: "cron",
status: "timed_out",
sourceId: "startup-timeout",
});
restoreStateDir();
stop(state);
expect(findTaskByRunId(`cron:startup-timeout:${now}`)).toMatchObject({
runtime: "cron",
status: "timed_out",
sourceId: "startup-timeout",
});
} finally {
restoreStateDir();
}
});
});