2015-12-31 18:33:35 -05:00
|
|
|
# frozen_string_literal: true
|
2015-07-14 00:55:24 -04:00
|
|
|
require_relative 'helper'
|
2019-07-24 13:52:54 -04:00
|
|
|
require 'sidekiq/rails'
|
|
|
|
require 'sidekiq/api'
|
2015-07-14 00:55:24 -04:00
|
|
|
|
2019-02-28 15:43:50 -05:00
|
|
|
describe 'ActiveJob' do
|
2019-07-24 13:52:54 -04:00
|
|
|
before do
|
|
|
|
Sidekiq.redis {|c| c.flushdb }
|
|
|
|
# need to force this since we aren't booting a Rails app
|
|
|
|
ActiveJob::Base.queue_adapter = :sidekiq
|
|
|
|
ActiveJob::Base.logger = nil
|
|
|
|
ActiveJob::Base.send(:include, ::Sidekiq::Worker::Options) unless ActiveJob::Base.respond_to?(:sidekiq_options)
|
|
|
|
end
|
|
|
|
|
2019-02-28 15:43:50 -05:00
|
|
|
it 'does not allow Sidekiq::Worker in AJ::Base classes' do
|
|
|
|
ex = assert_raises ArgumentError do
|
2019-07-20 20:17:15 -04:00
|
|
|
Class.new(ActiveJob::Base) do
|
|
|
|
include Sidekiq::Worker
|
|
|
|
end
|
|
|
|
end
|
2019-07-24 13:52:54 -04:00
|
|
|
assert_includes ex.message, "Sidekiq::Worker cannot be included"
|
2019-07-20 20:17:15 -04:00
|
|
|
end
|
|
|
|
|
2019-07-24 13:52:54 -04:00
|
|
|
it 'loads Sidekiq::Worker::Options in AJ::Base classes' do
|
|
|
|
aj = Class.new(ActiveJob::Base) do
|
|
|
|
queue_as :bar
|
2019-12-18 13:59:37 -05:00
|
|
|
sidekiq_options retry: 4, queue: 'foo', backtrace: 5
|
2019-07-20 20:17:15 -04:00
|
|
|
sidekiq_retry_in { |count, _exception| count * 10 }
|
|
|
|
sidekiq_retries_exhausted do |msg, _exception|
|
|
|
|
Sidekiq.logger.warn "Failed #{msg['class']} with #{msg['args']}: #{msg['error_message']}"
|
|
|
|
end
|
2019-02-28 15:43:50 -05:00
|
|
|
end
|
2019-07-24 13:52:54 -04:00
|
|
|
|
|
|
|
assert_equal 4, aj.get_sidekiq_options["retry"]
|
|
|
|
|
|
|
|
# When using ActiveJobs, you cannot set the queue with sidekiq_options, you must use
|
|
|
|
# queue_as or set(queue: ...). This is to avoid duplicate ways of doing the same thing.
|
|
|
|
instance = aj.perform_later(1, 2, 3)
|
|
|
|
q = Sidekiq::Queue.new("foo")
|
|
|
|
assert_equal 0, q.size
|
|
|
|
q = Sidekiq::Queue.new("bar")
|
|
|
|
assert_equal 1, q.size
|
|
|
|
assert_equal 24, instance.provider_job_id.size
|
2019-12-18 13:59:37 -05:00
|
|
|
|
|
|
|
job = q.first
|
|
|
|
assert_equal 4, job["retry"]
|
|
|
|
assert_equal 5, job["backtrace"]
|
2015-07-14 00:55:24 -04:00
|
|
|
end
|
|
|
|
end
|