Queue#drain method for better job tests
Created by: bogdan
Description
I want to be concise in my tests related to queue.
Using Queue#process
in tests lead to a complex code structure - similar to the one used in bull tests like here: https://github.com/OptimalBits/bull/blob/develop/test/test_queue.js#L111
This can got especially complex when job handlers create other jobs inside.
The easier way of doing things would be to have drain
method that suppose to process all jobs within the queue and return a promise that resolves when all jobs are processed:
queue.add({hello: 'world').then(() => queue.drain()).then(() => {
expect(something).toEqual(something)
});
The even simpler way to write tests would be use the #inline
method that makes all jobs processing inline:
queue.inline = true
queue.add({hello: 'world'}).then(() => {
// expecting the job is already processed
})
Inspired by: Sidekiq testing guide which has so much more staff to facilitate automated tests.
Are you interested in adding such functionality?