Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I test Sidekiq job failures?

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}

like image 818
Mark Bolusmjak Avatar asked Sep 30 '15 19:09

Mark Bolusmjak


1 Answers

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.

like image 125
Mike Perham Avatar answered Oct 16 '22 09:10

Mike Perham