Skip to content

Commit 169acf7

Browse files
committed
test(scheduler): regression test for same-cadence dedupe (no double-fire)
1 parent 4251e1b commit 169acf7

1 file changed

Lines changed: 14 additions & 0 deletions

File tree

storage/framework/core/scheduler/tests/scheduler.test.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,20 @@ describe('@stacksjs/scheduler', () => {
161161
})
162162
})
163163

164+
describe('dedupe — same job + same cadence scheduled twice (double-fire fix)', () => {
165+
it('creates one timer, not two (e.g. a Job `rate` + an explicit Scheduler.ts entry)', async () => {
166+
const taskFn = mock(() => {})
167+
new Schedule(taskFn).everySecond().withName('dupe-fix')
168+
new Schedule(taskFn).everySecond().withName('dupe-fix')
169+
170+
await new Promise(resolve => setTimeout(resolve, 2300))
171+
172+
// One timer → ~2 ticks in 2.3s; the bug (two timers) would be ~4.
173+
expect(taskFn.mock.calls.length).toBeLessThanOrEqual(3)
174+
expect(taskFn).toHaveBeenCalled()
175+
})
176+
})
177+
164178
describe('Static action() method', () => {
165179
it('should return an UntimedSchedule', () => {
166180
const result = Schedule.action('CleanupFiles')

0 commit comments

Comments
 (0)