test: simplify cron event call counts · openclaw/openclaw@10e425d
steipete
·
2026-05-09
·
via Recent Commits to openclaw:main
| Original file line number | Diff line number | Diff line change |
|---|
@@ -41,6 +41,19 @@ describe("CronService interval/cron jobs fire on time", () => {
|
41 | 41 | ); |
42 | 42 | }; |
43 | 43 | |
| 44 | +const countMainSystemEvents = ( |
| 45 | +enqueueSystemEvent: ReturnType<typeof vi.fn>, |
| 46 | +expectedText: string, |
| 47 | +): number => { |
| 48 | +let count = 0; |
| 49 | +for (const [text] of enqueueSystemEvent.mock.calls) { |
| 50 | +if (text === expectedText) { |
| 51 | +count++; |
| 52 | +} |
| 53 | +} |
| 54 | +return count; |
| 55 | +}; |
| 56 | + |
44 | 57 | it("fires an every-type main job when the timer fires a few ms late", async () => { |
45 | 58 | const store = await makeStorePath(); |
46 | 59 | const { cron, enqueueSystemEvent, finished } = createStartedCronServiceWithFinishedBarrier({ |
@@ -171,10 +184,8 @@ describe("CronService interval/cron jobs fire on time", () => {
|
171 | 184 | const sfRun = await cron.run("legacy-every", "due"); |
172 | 185 | expect(sfRun).toEqual({ ok: true, ran: true }); |
173 | 186 | |
174 | | -const sfRuns = enqueueSystemEvent.mock.calls.filter((args) => args[0] === "sf-tick").length; |
175 | | -const minuteRuns = enqueueSystemEvent.mock.calls.filter( |
176 | | -(args) => args[0] === "minute-tick", |
177 | | -).length; |
| 187 | +const sfRuns = countMainSystemEvents(enqueueSystemEvent, "sf-tick"); |
| 188 | +const minuteRuns = countMainSystemEvents(enqueueSystemEvent, "minute-tick"); |
178 | 189 | expect(minuteRuns).toBeGreaterThan(0); |
179 | 190 | expect(sfRuns).toBeGreaterThan(0); |
180 | 191 | |
|
此内容由惯性聚合(RSS阅读器)自动聚合整理,仅供阅读参考。 原文来自 — 版权归原作者所有。