lib/sidekiq/testing.rb in sidekiq-6.5.12 vs lib/sidekiq/testing.rb in sidekiq-7.0.0.beta1
- old
+ new
@@ -49,23 +49,14 @@
def inline?
__test_mode == :inline
end
def server_middleware
- @server_chain ||= Middleware::Chain.new
+ @server_chain ||= Middleware::Chain.new(Sidekiq.default_configuration)
yield @server_chain if block_given?
@server_chain
end
-
- def constantize(str)
- names = str.split("::")
- names.shift if names.empty? || names.first.empty?
-
- names.inject(Object) do |constant, name|
- constant.const_defined?(name) ? constant.const_get(name) : constant.const_missing(name)
- end
- end
end
end
# Default to fake testing to keep old behavior
Sidekiq::Testing.fake!
@@ -81,11 +72,11 @@
Queues.push(job["queue"], job["class"], job)
end
true
elsif Sidekiq::Testing.inline?
payloads.each do |job|
- klass = Sidekiq::Testing.constantize(job["class"])
+ klass = Object.const_get(job["class"])
job["id"] ||= SecureRandom.hex(12)
job_hash = Sidekiq.load_json(Sidekiq.dump_json(job))
klass.process_job(job_hash)
end
true
@@ -216,30 +207,14 @@
# assert_equal 0, HardJob.jobs.size
# HardJob.perform_async(:something)
# assert_equal 1, HardJob.jobs.size
# assert_equal :something, HardJob.jobs[0]['args'][0]
#
- # assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
- # MyMailer.delay.send_welcome_email('foo@example.com')
- # assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
- #
# You can also clear and drain all job types:
#
- # assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
- # assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
- #
- # MyMailer.delay.send_welcome_email('foo@example.com')
- # MyModel.delay.do_something_hard
- #
- # assert_equal 1, Sidekiq::Extensions::DelayedMailer.jobs.size
- # assert_equal 1, Sidekiq::Extensions::DelayedModel.jobs.size
- #
# Sidekiq::Worker.clear_all # or .drain_all
#
- # assert_equal 0, Sidekiq::Extensions::DelayedMailer.jobs.size
- # assert_equal 0, Sidekiq::Extensions::DelayedModel.jobs.size
- #
# This can be useful to make sure jobs don't linger between tests:
#
# RSpec.configure do |config|
# config.before(:each) do
# Sidekiq::Job.clear_all
@@ -316,27 +291,24 @@
def drain_all
while jobs.any?
job_classes = jobs.map { |job| job["class"] }.uniq
job_classes.each do |job_class|
- Sidekiq::Testing.constantize(job_class).drain
+ Object.const_get(job_class).drain
end
end
end
end
end
module TestingExtensions
def jobs_for(klass)
jobs.select do |job|
marshalled = job["args"][0]
- marshalled.index(klass.to_s) && YAML.load(marshalled)[0] == klass
+ marshalled.index(klass.to_s) && YAML.safe_load(marshalled)[0] == klass
end
end
end
-
- Sidekiq::Extensions::DelayedMailer.extend(TestingExtensions) if defined?(Sidekiq::Extensions::DelayedMailer)
- Sidekiq::Extensions::DelayedModel.extend(TestingExtensions) if defined?(Sidekiq::Extensions::DelayedModel)
end
if defined?(::Rails) && Rails.respond_to?(:env) && !Rails.env.test? && !$TESTING
warn("⛔️ WARNING: Sidekiq testing API enabled, but this is not the test environment. Your jobs will not go to Redis.", uplevel: 1)
end