mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-06 07:20:43 +00:00
test: follow deferred cron startup catch-up
This commit is contained in:
@@ -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();
|
||||
|
||||
@@ -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();
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user