sidekiq-superworker icon indicating copy to clipboard operation
sidekiq-superworker copied to clipboard

Integration testing problems

Open karloscodes opened this issue 10 years ago • 3 comments

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?

karloscodes avatar Jun 25 '14 21:06 karloscodes

Running into the same kind of issue now. Did you find a solution that works for you?

HParker avatar May 14 '15 21:05 HParker

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

skwp avatar Sep 03 '15 21:09 skwp

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

m-pod avatar Jan 29 '16 14:01 m-pod