# frozen_string_literal: true SIDEKIQ_BATCH_CALLBACK_PATTERN = /\Ab-[a-zA-Z0-9_\-]{14}\z/.freeze SIDEKIQ_BATCH_DATA_PATTERN = /\Abatches\z/.freeze SIDEKIQ_BATCH_JOBS_PATTERN = /\Ab-[a-zA-Z0-9_\-]{14}-jids\z/.freeze SIDEKIQ_LIMITER_DATA_PATTERN = /\Almtr-c-/.freeze SIDEKIQ_LIMITER_JOBS_PATTERN = /\Almtr-cfree-/.freeze # rubocop:disable Metrics/BlockNesting ::RSpec.configure do |config| # rubocop:disable Metrics/BlockLength config.before(:each, queue: ->(v) { !v.nil? }) do |example| # rubocop:disable Metrics/BlockLength config.rspeckled_logger.debug("Before Each - Start - #{__FILE__}") # Changes Any Limiters Created to Be Unlimited if defined?(::Sidekiq::Limiter) allow(::Sidekiq::Limiter).to receive(:concurrent) .and_return(::Sidekiq::Limiter::Unlimited.new) allow(::Sidekiq::Limiter).to receive(:bucket) .and_return(::Sidekiq::Limiter::Unlimited.new) allow(::Sidekiq::Limiter).to receive(:window) .and_return(::Sidekiq::Limiter::Unlimited.new) end # Clears out the jobs for tests using the fake testing ::Sidekiq::Worker.clear_all ::Sidekiq::Queues.clear_all ::Sidekiq.redis do |client| client.scan_each(match: '*') do |key| next unless key.match?(SIDEKIQ_BATCH_CALLBACK_PATTERN) || key.match?(SIDEKIQ_BATCH_DATA_PATTERN) || key.match?(SIDEKIQ_BATCH_JOBS_PATTERN) || key.match?(SIDEKIQ_LIMITER_DATA_PATTERN) || key.match?(SIDEKIQ_LIMITER_JOBS_PATTERN) client.del(key) end end # rubocop:disable Lint/DuplicateBranch if %i{stub fake}.include?(example.metadata[:queue]) ::Sidekiq::Testing.fake! elsif %i{inline immediately_execute}.include?(example.metadata[:queue]) || %i{system feature}.include?(example.metadata[:type]) ::Sidekiq::Testing.inline! else ::Sidekiq::Testing.fake! end # rubocop:enable Lint/DuplicateBranch config.rspeckled_logger.debug("Before Each - End - #{__FILE__}") end config.after(:each, queue: ->(v) { !v.nil? }) do |_example| config.rspeckled_logger.debug("After Each - Start - #{__FILE__}") ::Sidekiq::Testing.fake! config.rspeckled_logger.debug("After Each - End - #{__FILE__}") end end # rubocop:enable Metrics/BlockNesting