-
Notifications
You must be signed in to change notification settings - Fork 414
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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); | ||
}); | ||
|
||
it('worker should start processing repeatable jobs after drain', async function () { | ||
await queue.upsertJobScheduler('scheduler-test', { | ||
pattern: '* * * * *', | ||
immediately: true, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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' }); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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(); | ||
}); | ||
}); |
There was a problem hiding this comment.
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: