sidekiq-superworker
sidekiq-superworker copied to clipboard
Integration testing problems
Question: I have set Sidekiq::Testing.inline! under spec_helper for my integration tests, is there anything similar on superworkers? I need to run workers and wait for they to finish in order to perform some asserts, how can this be achieved?
Running into the same kind of issue now. Did you find a solution that works for you?
This is not particularly elegant, but you can override the Superworker in your own project like this (put this in spec_helper or some required file from there):
module Sidekiq
module Superworker
class SuperjobProcessor
def self.create(superjob_id, superworker_class_name, args, subjobs, options={})
if Sidekiq::Testing.inline?
subjobs.each do |subjob|
SubjobProcessor.enqueue(subjob)
end
else
super
end
end
end
end
end
With batched workers this worked for me by monkey_patching it in spec_helper like @skwp proposed:
require 'sidekiq-superworker'
module Sidekiq
module Superworker
class SuperjobProcessor
def self.create(superjob_id, superworker_class_name, args, subjobs, options={})
if Sidekiq::Testing.inline?
subjobs.each do |subjob|
SubjobProcessor.enqueue(subjob) unless subjob.subworker_class == 'batch_child'
end
else
super
end
end
end
end
end