mirror of
https://github.com/mperham/sidekiq.git
synced 2022-11-09 13:52:34 -05:00
1eb0c80ca0
If you are passing arguments like time objects that serialize to strings but don't deserialize back automatically, inline testing was passing the objects through raw meaning different behavior in tests vs. production. Now the inline wrapper does a round trip through json.
37 lines
907 B
Ruby
37 lines
907 B
Ruby
module Sidekiq
|
|
module Worker
|
|
|
|
##
|
|
# The Sidekiq inline infrastructure overrides the 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
|
|
#
|
|
module ClassMethods
|
|
alias_method :perform_async_old, :perform_async
|
|
def perform_async(*args)
|
|
new.perform(*Sidekiq.load_json(Sidekiq.dump_json(args)))
|
|
true
|
|
end
|
|
end
|
|
end
|
|
end
|