A job in sidekiq, upon exception, will be put on the retry queue.
Because of that, and because the task is run asynchronously, MyWorker.perform_async(...)
can never throw an exception generated in the task code.
In testing, however, an exception that occurs in the task does not cause the task to be put in the retry queue. The exception bubbles up out of perform_async
.
So what happens in tests is something that cannot possible occur when running the code.
What, then, is the best way to test code that triggers jobs that can fail and be put on the retry queue?
Note that the following seems to have no effect in testing:Sidekiq.default_worker_options = { :retry => true}
It's designed to be hard because you shouldn't do it. You should not be testing Sidekiq functionality. Test your own code, not features provided by other libraries/frameworks.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With