socialpandas / sidekiq-superworker

Directed acyclic graphs of Sidekiq jobs
MIT License
438 stars 34 forks source link

Integration testing problems #26

Open karloscodes opened 10 years ago

karloscodes commented 10 years ago

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?

HParker commented 9 years ago

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

skwp commented 9 years ago

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
m-pod commented 8 years ago

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