Sha256: 36cf9326bc1f527babede04afc6ec8b99999f4e655dba7ae614bbbddd0c58c0b

Contents?: true

Size: 982 Bytes

Versions: 7

Compression:

Stored size: 982 Bytes

Contents

module Sidekiq
  class Client

    ##
    # The Sidekiq inline infrastructure overrides perform_async so that it
    # actually calls perform instead. This allows workers to be run inline in a
    # testing environment.
    #
    # This is similar to `Resque.inline = true` functionality.
    #
    # Example:
    #
    #   require 'sidekiq/testing/inline'
    #
    #   $external_variable = 0
    #
    #   class ExternalWorker
    #     include Sidekiq::Worker
    #
    #     def perform
    #       $external_variable = 1
    #     end
    #   end
    #
    #   assert_equal 0, $external_variable
    #   ExternalWorker.perform_async
    #   assert_equal 1, $external_variable
    #
    singleton_class.class_eval do
      alias_method :raw_push_old, :raw_push
      def raw_push(normed, payload)
        Array.wrap(payload).each do |hash|
          normed['class'].constantize.new.perform(*Sidekiq.load_json(hash)['args'])
        end

        true
      end
    end
  end
end

Version data entries

7 entries across 7 versions & 1 rubygems

Version Path
sidekiq-2.6.5 lib/sidekiq/testing/inline.rb
sidekiq-2.6.4 lib/sidekiq/testing/inline.rb
sidekiq-2.6.3 lib/sidekiq/testing/inline.rb
sidekiq-2.6.2 lib/sidekiq/testing/inline.rb
sidekiq-2.6.1 lib/sidekiq/testing/inline.rb
sidekiq-2.6.0 lib/sidekiq/testing/inline.rb
sidekiq-2.5.4 lib/sidekiq/testing/inline.rb