Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: prevent jobs from stopping unexpectedly #963

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions tests/cron.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,30 @@ describe('cron', () => {
sinon.restore();
});

it('should not stop job if sendAt takes time to complete (#962)', () => {
const EVERY = 5;
const TICK = EVERY * 1000;
const DELAY = 350;

const date = new Date('2025-02-23T14:00:00.000Z');
const clock = sinon.useFakeTimers(date.getTime());

sinon
.stub(Date, 'now')
.onCall(0)
.returns(date.getTime())
.onCall(1)
.returns(date.getTime() + TICK)
.onCall(2)
.returns(date.getTime() + TICK + DELAY);

const job = new CronJob(`*/${EVERY} * * * * *`, callback, null, true);
clock.tick(TICK);

expect(job.isActive).toBe(true);
expect(callback).toHaveBeenCalledTimes(1);
});

describe('with seconds', () => {
it('should run every second (* * * * * *)', () => {
const clock = sinon.useFakeTimers();
Expand Down
Loading