mirror of
https://github.com/openclaw/openclaw.git
synced 2026-05-12 06:30:43 +00:00
test: simplify cron event call counts
This commit is contained in:
@@ -41,6 +41,19 @@ describe("CronService interval/cron jobs fire on time", () => {
|
||||
);
|
||||
};
|
||||
|
||||
const countMainSystemEvents = (
|
||||
enqueueSystemEvent: ReturnType<typeof vi.fn>,
|
||||
expectedText: string,
|
||||
): number => {
|
||||
let count = 0;
|
||||
for (const [text] of enqueueSystemEvent.mock.calls) {
|
||||
if (text === expectedText) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
return count;
|
||||
};
|
||||
|
||||
it("fires an every-type main job when the timer fires a few ms late", async () => {
|
||||
const store = await makeStorePath();
|
||||
const { cron, enqueueSystemEvent, finished } = createStartedCronServiceWithFinishedBarrier({
|
||||
@@ -171,10 +184,8 @@ describe("CronService interval/cron jobs fire on time", () => {
|
||||
const sfRun = await cron.run("legacy-every", "due");
|
||||
expect(sfRun).toEqual({ ok: true, ran: true });
|
||||
|
||||
const sfRuns = enqueueSystemEvent.mock.calls.filter((args) => args[0] === "sf-tick").length;
|
||||
const minuteRuns = enqueueSystemEvent.mock.calls.filter(
|
||||
(args) => args[0] === "minute-tick",
|
||||
).length;
|
||||
const sfRuns = countMainSystemEvents(enqueueSystemEvent, "sf-tick");
|
||||
const minuteRuns = countMainSystemEvents(enqueueSystemEvent, "minute-tick");
|
||||
expect(minuteRuns).toBeGreaterThan(0);
|
||||
expect(sfRuns).toBeGreaterThan(0);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user