Skip to content

Instantly share code, notes, and snippets.

@tejasbubane
Created January 20, 2022 19:47
Show Gist options
  • Save tejasbubane/09c1412b88ce1e9cb3dacff0817119d2 to your computer and use it in GitHub Desktop.
Save tejasbubane/09c1412b88ce1e9cb3dacff0817119d2 to your computer and use it in GitHub Desktop.
Testing nested workers in sidekiq
# 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