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

Queue#drain method for better job tests #1548

Open
bogdan opened this issue Nov 7, 2019 · 1 comment
Open

Queue#drain method for better job tests #1548

bogdan opened this issue Nov 7, 2019 · 1 comment

Comments

@bogdan
Copy link

bogdan commented Nov 7, 2019

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?

@stale
Copy link

stale bot commented Jul 12, 2021

This issue has been automatically marked as stale because it has not had recent activity. It will be closed if no further activity occurs. Thank you for your contributions.

@stale stale bot added the wontfix label Jul 12, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants