A large part of my application relies on background jobs to process user's websites, so I need to write some tests to cover these.
First question is how to test code that's in a Sidekiq worker class, for example app/workers/some_worker.rb
class SomeWorker
include Sidekiq::Worker
def perform(model_id)
...
end
end
Secondly, how do I stub code such as the following so I don't need to actually run workers and slow down my tests?
response = HTTParty.get("http://users-site.com", timeout: 30)
To test your Sidekiq Worker jobs array, run WorkerNameHere.jobs in terminal and see if it contains your job with your jid. If it does, then it was enqueued in Sidekiq to be run as a job.
To run sidekiq, you will need to open a terminal, navigate to your application's directory, and start the sidekiq process, exactly as you would start a web server for the application itself. When the command executes you will see a message that sidekiq has started.
On the browser, goto ==> http://localhost:{port}/sidekiq/recurring-jobs . where {port} is the port your application is running in. You will see the list of scheduled jobs for your application and some other details about it. Show activity on this post.
Read the Testing page in the Sidekiq wiki.
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