Created
January 20, 2022 19:47
-
-
Save tejasbubane/09c1412b88ce1e9cb3dacff0817119d2 to your computer and use it in GitHub Desktop.
Testing nested workers in sidekiq
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Prepared for https://stackoverflow.com/questions/70790708/testing-enque-of-nested-worker-from-another-sidekiq-worker | |
require 'sidekiq' | |
require 'sidekiq/testing' | |
require 'rspec' | |
class WorkerOne | |
include Sidekiq::Worker | |
def perform(arg_1, arg_2) | |
# some calculation figure out arg_3 | |
arg_3 = arg_1 + 10 | |
WorkerTwo.perform_async(arg_3, arg_2) | |
end | |
end | |
class WorkerTwo | |
include Sidekiq::Worker | |
def perform(arg_3, arg_2) | |
# some heavy lifting | |
end | |
end | |
RSpec.describe WorkerOne do | |
describe '#perform' do | |
it 'schedules WorkerTwo' do | |
expect { | |
WorkerOne.new.perform(10, 15) | |
}.to change(WorkerTwo.jobs, :size).by(1) | |
end | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment