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

test: starts immediately after remove job scheduler #2805

Merged
merged 1 commit into from
Oct 7, 2024
Merged
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
71 changes: 71 additions & 0 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -751,6 +751,77 @@ describe('Job Scheduler', function () {
delayStub.restore();
});

it('should start immediately even after removing the job scheduler and adding it again', async function () {
const date = new Date('2017-02-07 9:24:00');
this.clock.setSystemTime(date);
const nextTick = 2 * ONE_SECOND;

let worker: Worker;
const processing1 = new Promise<void>((resolve, reject) => {
worker = new Worker(
queueName,
async (job: Job) => {
this.clock.tick(nextTick);

try {
expect(job.opts.delay).to.be.eq(0);
resolve();
} catch (error) {
reject(error);
}
},
{ connection, prefix },
);
});

await queue.upsertJobScheduler(
'repeat',
{
every: 2000,
immediately: true,
},
{ data: { foo: 'bar' } },
);

this.clock.tick(1265);

await processing1;

await worker!.close();

await queue.removeJobScheduler('repeat');

const processing2 = new Promise<void>((resolve, reject) => {
worker = new Worker(
queueName,
async (job: Job) => {
this.clock.tick(nextTick);

try {
expect(job.opts.delay).to.be.eq(0);
resolve();
} catch (error) {
reject(error);
}
},
{ connection, prefix },
);
});

await queue.upsertJobScheduler(
'repeat',
{
every: 2000,
immediately: true,
},
{ data: { foo: 'bar' } },
);

await processing2;

await worker!.close();
});

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

Expand Down
Loading