Skip to content

Commit

Permalink
test: restore test to validate no re-adding scheduler job when it is …
Browse files Browse the repository at this point in the history
…removed
  • Loading branch information
roggervalf committed Jan 7, 2025
1 parent d98dc47 commit 31068ae
Showing 1 changed file with 18 additions and 32 deletions.
50 changes: 18 additions & 32 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2009,56 +2009,42 @@ describe('Job Scheduler', function () {
});
});

// This test is flaky and too complex we need something simpler that tests the same thing
it.skip('should not re-add a repeatable job after it has been removed', async function () {
const repeat = await queue.repeat;

let worker: Worker;
const jobId = 'xxxx';
it('should not re-add a repeatable job after it has been removed', async function () {
const date = new Date('2017-02-07 9:24:00');
const nextTick = 2 * ONE_SECOND + 100;
const addNextRepeatableJob = repeat.updateRepeatableJob;
this.clock.setSystemTime(date);

const repeatOpts = { pattern: '*/2 * * * * *' };

const afterRemoved = new Promise<void>(async resolve => {
worker = new Worker(
queueName,
async () => {
const repeatWorker = await worker.repeat;
(<unknown>repeatWorker.updateRepeatableJob) = async (
...args: [string, unknown, JobsOptions, boolean?]
) => {
// In order to simulate race condition
// Make removeRepeatables happen any time after a moveToX is called
await queue.removeRepeatable('test', repeatOpts, jobId);

// addNextRepeatableJob will now re-add the removed repeatable
const result = await addNextRepeatableJob.apply(repeat, args);
resolve();
return result;
};
},
{ connection, prefix },
);
const worker = new Worker(
queueName,
async () => {
await queue.removeJobScheduler('test');
},
{ connection, prefix },
);

const afterRemoved = new Promise<void>(async resolve => {
worker.on('completed', () => {
this.clock.tick(nextTick);
resolve();
});
});

await queue.add('test', { foo: 'bar' }, { repeat: repeatOpts, jobId });
await queue.upsertJobScheduler('test', repeatOpts, {
data: { foo: 'bar' },
});

this.clock.tick(nextTick);

await afterRemoved;

const jobs = await queue.getRepeatableJobs();
// Repeatable job was recreated
const jobs = await queue.getJobSchedulers();
expect(jobs.length).to.eql(0);

await worker!.close();
const delayedCount = await queue.getDelayedCount();
expect(delayedCount).to.eql(0);

await worker.close();
});

it('should allow adding a repeatable job after removing it', async function () {
Expand Down

0 comments on commit 31068ae

Please sign in to comment.