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

add testing option to count the number of matched messages #26

Closed
tcoopman opened this issue Jul 8, 2019 · 4 comments
Closed

add testing option to count the number of matched messages #26

tcoopman opened this issue Jul 8, 2019 · 4 comments

Comments

@tcoopman
Copy link

tcoopman commented Jul 8, 2019

In my test I sometimes want to check that there is only one message enqueued and not more. A method to test for this would be great.

@sorentwo
Copy link
Member

sorentwo commented Jul 8, 2019

I've thought about this a bit today and I believe both #25 and #26 can be accomplished with the addition of a get_enqueued/1 function. Within tests you would use it like this:

# Make an assertion that there is a single job with the args `%{id: 1}`
assert [%{args: %{id: 1}}] = get_enqueued(worker: MyWorker, queue: "foobar")

# Make an assertion that there is exactly one matching job
assert [%Oban.Job{}] = get_enqueued(worker: MyWorker, queue: "foobar")

This is flexible and allows you to make any assertions that you like in your tests.

@tcoopman
Copy link
Author

tcoopman commented Jul 8, 2019

That sounds very fine

sorentwo added a commit that referenced this issue Jul 9, 2019
Added `all_enqueued/1` helper for testing. The helper returns a list of
jobs matching the provided criteria. This makes it possible to test
using pattern matching, which is more flexible than a literal match
within the database.

Closes #25 and #26
@sorentwo
Copy link
Member

sorentwo commented Jul 9, 2019

Thanks for the suggestion. Between the pattern matching suggestion here and in #25 I believe it is possible to write more robust (though verbose) tests when necessary.

Please take a look at 3c5ed47 and let me know if it works for you.

@sorentwo sorentwo closed this as completed Jul 9, 2019
@tcoopman
Copy link
Author

tcoopman commented Jul 9, 2019

Thanks, this is perfect. I've already tested it, and it works great.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants