debian-mirror-gitlab/spec/workers/every_sidekiq_worker_spec.rb

67 lines
3 KiB
Ruby
Raw Normal View History

2019-07-07 11:18:12 +05:30
# frozen_string_literal: true
2016-11-03 12:29:30 +05:30
require 'spec_helper'
describe 'Every Sidekiq worker' do
it 'does not use the default queue' do
2018-03-17 18:26:18 +05:30
expect(Gitlab::SidekiqConfig.workers.map(&:queue)).not_to include('default')
2016-11-03 12:29:30 +05:30
end
it 'uses the cronjob queue when the worker runs as a cronjob' do
2018-03-17 18:26:18 +05:30
expect(Gitlab::SidekiqConfig.cron_workers.map(&:queue)).to all(start_with('cronjob:'))
end
2016-11-03 12:29:30 +05:30
2019-02-15 15:39:39 +05:30
it 'has its queue in Gitlab::SidekiqConfig::QUEUE_CONFIG_PATHS', :aggregate_failures do
2018-03-17 18:26:18 +05:30
file_worker_queues = Gitlab::SidekiqConfig.worker_queues.to_set
2016-11-03 12:29:30 +05:30
2018-03-17 18:26:18 +05:30
worker_queues = Gitlab::SidekiqConfig.workers.map(&:queue).to_set
2018-11-08 19:23:39 +05:30
worker_queues << ActionMailer::DeliveryJob.new.queue_name
2018-03-17 18:26:18 +05:30
worker_queues << 'default'
missing_from_file = worker_queues - file_worker_queues
2019-02-15 15:39:39 +05:30
expect(missing_from_file).to be_empty, "expected #{missing_from_file.to_a.inspect} to be in Gitlab::SidekiqConfig::QUEUE_CONFIG_PATHS"
2018-03-17 18:26:18 +05:30
unncessarily_in_file = file_worker_queues - worker_queues
2019-02-15 15:39:39 +05:30
expect(unncessarily_in_file).to be_empty, "expected #{unncessarily_in_file.to_a.inspect} not to be in Gitlab::SidekiqConfig::QUEUE_CONFIG_PATHS"
2016-11-03 12:29:30 +05:30
end
2018-03-17 18:26:18 +05:30
it 'has its queue or namespace in config/sidekiq_queues.yml', :aggregate_failures do
config_queues = Gitlab::SidekiqConfig.config_queues.to_set
Gitlab::SidekiqConfig.workers.each do |worker|
queue = worker.queue
queue_namespace = queue.split(':').first
2016-11-03 12:29:30 +05:30
2018-03-17 18:26:18 +05:30
expect(config_queues).to include(queue).or(include(queue_namespace))
2016-11-03 12:29:30 +05:30
end
end
2019-12-21 20:55:43 +05:30
describe "feature category declarations" do
let(:feature_categories) do
YAML.load_file(Rails.root.join('config', 'feature_categories.yml')).map(&:to_sym).to_set
end
# All Sidekiq worker classes should declare a valid `feature_category`
# or explicitely be excluded with the `feature_category_not_owned!` annotation.
# Please see doc/development/sidekiq_style_guide.md#Feature-Categorization for more details.
it 'has a feature_category or feature_category_not_owned! attribute', :aggregate_failures do
Gitlab::SidekiqConfig.workers.each do |worker|
expect(worker.get_feature_category).to be_a(Symbol), "expected #{worker.inspect} to declare a feature_category or feature_category_not_owned!"
end
end
# All Sidekiq worker classes should declare a valid `feature_category`.
# The category should match a value in `config/feature_categories.yml`.
# Please see doc/development/sidekiq_style_guide.md#Feature-Categorization for more details.
it 'has a feature_category that maps to a value in feature_categories.yml', :aggregate_failures do
workers_with_feature_categories = Gitlab::SidekiqConfig.workers
.select(&:get_feature_category)
.reject(&:feature_category_not_owned?)
workers_with_feature_categories.each do |worker|
expect(feature_categories).to include(worker.get_feature_category), "expected #{worker.inspect} to declare a valid feature_category, but got #{worker.get_feature_category}"
end
end
end
2016-11-03 12:29:30 +05:30
end