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(job-scheduler): add tests with drain and promote for job scheduler #2944

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
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
45 changes: 45 additions & 0 deletions tests/test_job_scheduler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1896,4 +1896,49 @@ describe('Job Scheduler', function () {
await processing;
await worker.close();
});

it('should schedule next repeatable job after promote', async function () {
await queue.upsertJobScheduler('scheduler-test', { every: 50000 });

await queue.promoteJobs();

const waitingCount = await queue.getWaitingCount();
expect(waitingCount).to.be.equal(1);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

to check that at least the next repeatable was scheduled you may need to check the delayed count as well, so after this line you can add:

const delayedCount = await queue.getDeleayedCount();
expect(delayedCount).to.be.equal(1);

});

it('worker should start processing repeatable jobs after drain', async function () {
await queue.upsertJobScheduler('scheduler-test', {
pattern: '* * * * *',
immediately: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

immediately happens by default when using every option, no need to pass it

});
const worker = new Worker(queueName, async () => {}, { connection });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

maybe initialize worker after drain operation as worker could take the first iteration as quick as possible

await worker.waitUntilReady();

await queue.drain(true);

await queue.upsertJobScheduler('scheduler-test', {
pattern: '* * * * *',
immediately: true,
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this option is not needed when using every option as it happens by default

});

const completing = new Promise<void>((resolve, reject) => {
worker.once('completed', async job => {
try {
expect(job).to.be.ok;
expect(job.data.foo).to.be.eql('bar');
} catch (err) {
reject(err);
}
resolve();
});
});

const job = await queue.add('test', { foo: 'bar' });
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this addition looks like it's not needed but you may need to check the completion of the scheduled job from scheduler

expect(job.id).to.be.ok;
expect(job.data.foo).to.be.eql('bar');

await completing;

await worker.close();
});
});
Loading