2019-08-22 10:57:44 +00:00
|
|
|
# frozen_string_literal: true
|
|
|
|
|
2019-08-29 07:56:52 +00:00
|
|
|
require 'spec_helper'
|
2017-11-28 16:08:30 +00:00
|
|
|
|
|
|
|
describe Gitlab::SidekiqConfig do
|
|
|
|
describe '.workers' do
|
|
|
|
it 'includes all workers' do
|
2020-01-22 12:08:40 +00:00
|
|
|
worker_classes = described_class.workers.map(&:klass)
|
2017-11-28 16:08:30 +00:00
|
|
|
|
2020-01-22 12:08:40 +00:00
|
|
|
expect(worker_classes).to include(PostReceive)
|
|
|
|
expect(worker_classes).to include(MergeWorker)
|
2017-11-28 16:08:30 +00:00
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.worker_queues' do
|
|
|
|
it 'includes all queues' do
|
|
|
|
queues = described_class.worker_queues
|
|
|
|
|
|
|
|
expect(queues).to include('post_receive')
|
|
|
|
expect(queues).to include('merge')
|
2017-11-28 16:16:50 +00:00
|
|
|
expect(queues).to include('cronjob:stuck_import_jobs')
|
2017-11-28 16:08:30 +00:00
|
|
|
expect(queues).to include('mailers')
|
|
|
|
expect(queues).to include('default')
|
|
|
|
end
|
|
|
|
end
|
2017-11-28 16:16:50 +00:00
|
|
|
|
2020-01-22 12:08:40 +00:00
|
|
|
describe '.workers_for_all_queues_yml' do
|
|
|
|
it 'returns a tuple with FOSS workers first' do
|
|
|
|
expect(described_class.workers_for_all_queues_yml.first)
|
|
|
|
.to include(an_object_having_attributes(queue: 'post_receive'))
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.all_queues_yml_outdated?' do
|
2020-01-28 15:08:36 +00:00
|
|
|
let(:workers) do
|
|
|
|
[
|
2020-01-22 12:08:40 +00:00
|
|
|
MergeWorker,
|
2020-01-28 15:08:36 +00:00
|
|
|
PostReceive,
|
2020-01-22 12:08:40 +00:00
|
|
|
ProcessCommitWorker
|
|
|
|
].map { |worker| described_class::Worker.new(worker, ee: false) }
|
2020-01-28 15:08:36 +00:00
|
|
|
end
|
2020-01-22 12:08:40 +00:00
|
|
|
|
2020-01-28 15:08:36 +00:00
|
|
|
before do
|
2020-01-22 12:08:40 +00:00
|
|
|
allow(described_class).to receive(:workers).and_return(workers)
|
|
|
|
allow(Gitlab).to receive(:ee?).and_return(false)
|
|
|
|
end
|
|
|
|
|
2020-01-28 15:08:36 +00:00
|
|
|
it 'returns true if the YAML file does not matcph the application code' do
|
|
|
|
allow(YAML).to receive(:load_file)
|
2020-01-22 12:08:40 +00:00
|
|
|
.with(described_class::FOSS_QUEUE_CONFIG_PATH)
|
2020-01-28 15:08:36 +00:00
|
|
|
.and_return(workers.first(2).map(&:to_yaml))
|
2020-01-22 12:08:40 +00:00
|
|
|
|
|
|
|
expect(described_class.all_queues_yml_outdated?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the YAML file matches the application code' do
|
2020-01-28 15:08:36 +00:00
|
|
|
allow(YAML).to receive(:load_file)
|
2020-01-22 12:08:40 +00:00
|
|
|
.with(described_class::FOSS_QUEUE_CONFIG_PATH)
|
2020-01-28 15:08:36 +00:00
|
|
|
.and_return(workers.map(&:to_yaml))
|
2020-01-22 12:08:40 +00:00
|
|
|
|
|
|
|
expect(described_class.all_queues_yml_outdated?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
2020-01-24 18:09:00 +00:00
|
|
|
|
|
|
|
describe '.queues_for_sidekiq_queues_yml' do
|
|
|
|
before do
|
|
|
|
workers = [
|
|
|
|
Namespaces::RootStatisticsWorker,
|
|
|
|
Namespaces::ScheduleAggregationWorker,
|
|
|
|
MergeWorker,
|
|
|
|
ProcessCommitWorker
|
|
|
|
].map { |worker| described_class::Worker.new(worker, ee: false) }
|
|
|
|
|
|
|
|
allow(described_class).to receive(:workers).and_return(workers)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns queues and weights, aggregating namespaces with the same weight' do
|
|
|
|
expected_queues = [
|
|
|
|
['merge', 5],
|
|
|
|
['process_commit', 3],
|
|
|
|
['update_namespace_statistics', 1]
|
|
|
|
]
|
|
|
|
|
|
|
|
expect(described_class.queues_for_sidekiq_queues_yml).to eq(expected_queues)
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
|
|
|
describe '.sidekiq_queues_yml_outdated?' do
|
|
|
|
before do
|
|
|
|
workers = [
|
|
|
|
Namespaces::RootStatisticsWorker,
|
|
|
|
Namespaces::ScheduleAggregationWorker,
|
|
|
|
MergeWorker,
|
|
|
|
ProcessCommitWorker
|
|
|
|
].map { |worker| described_class::Worker.new(worker, ee: false) }
|
|
|
|
|
|
|
|
allow(described_class).to receive(:workers).and_return(workers)
|
|
|
|
end
|
|
|
|
|
|
|
|
let(:expected_queues) do
|
|
|
|
[
|
|
|
|
['merge', 5],
|
|
|
|
['process_commit', 3],
|
|
|
|
['update_namespace_statistics', 1]
|
|
|
|
]
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns true if the YAML file does not match the application code' do
|
2020-01-28 15:08:36 +00:00
|
|
|
allow(YAML).to receive(:load_file)
|
2020-01-24 18:09:00 +00:00
|
|
|
.with(described_class::SIDEKIQ_QUEUES_PATH)
|
2020-01-28 15:08:36 +00:00
|
|
|
.and_return(queues: expected_queues.reverse)
|
2020-01-24 18:09:00 +00:00
|
|
|
|
|
|
|
expect(described_class.sidekiq_queues_yml_outdated?).to be(true)
|
|
|
|
end
|
|
|
|
|
|
|
|
it 'returns false if the YAML file matches the application code' do
|
2020-01-28 15:08:36 +00:00
|
|
|
allow(YAML).to receive(:load_file)
|
2020-01-24 18:09:00 +00:00
|
|
|
.with(described_class::SIDEKIQ_QUEUES_PATH)
|
2020-01-28 15:08:36 +00:00
|
|
|
.and_return(queues: expected_queues)
|
2020-01-24 18:09:00 +00:00
|
|
|
|
|
|
|
expect(described_class.sidekiq_queues_yml_outdated?).to be(false)
|
|
|
|
end
|
|
|
|
end
|
2017-11-28 16:08:30 +00:00
|
|
|
end
|