Skip to content

Commit

Permalink
test(scheduler): add case where startDate is the same as first iterat…
Browse files Browse the repository at this point in the history
…ion (#2871)
  • Loading branch information
roggervalf authored Oct 29, 2024
1 parent 0547f7a commit d7d2a68
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -952,6 +952,70 @@ describe('Job Scheduler', function () {
delayStub.restore();
});

it('should repeat once a day after startDate that is equal as first iteration', async function () {
this.timeout(8000);

const date = new Date('2024-10-10T16:30:00.000+05:30');
this.clock.setSystemTime(date);

const nextTick = ONE_DAY + 10 * ONE_SECOND;
const delay = 5 * ONE_HOUR + 500;

let counter = 0;
const worker = new Worker(
queueName,
async () => {
this.clock.tick(nextTick);
},
{
autorun: false,
connection,
prefix,
skipStalledCheck: true,
skipLockRenewal: true,
},
);
const delayStub = sinon.stub(worker, 'delay').callsFake(async () => {
console.log('delay');
});

let prev: Job;
const completing = new Promise<void>((resolve, reject) => {
worker.on('completed', async job => {
if (counter === 1) {
expect(prev.timestamp).to.be.lt(job.timestamp);
expect(job.processedOn! - prev.timestamp).to.be.gte(delay);
} else if (prev) {
expect(prev.timestamp).to.be.lt(job.timestamp);
expect(job.processedOn! - prev.timestamp).to.be.gte(ONE_DAY);
}
prev = job;

counter++;
if (counter == 5) {
resolve();
}
});
});

await queue.upsertJobScheduler(
'repeat',
{
pattern: '30 19 * * *',
startDate: '2024-10-10T19:30:00.000+05:30',
tz: 'Asia/Calcutta',
},
{ data: { foo: 'bar' } },
);
this.clock.tick(delay + ONE_DAY);

worker.run();

await completing;
await worker.close();
delayStub.restore();
});

it('should repeat once a day for 5 days', async function () {
this.timeout(8000);

Expand Down

0 comments on commit d7d2a68

Please sign in to comment.