diff options
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/sidekiq_config/worker_spec.rb | 84 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_config_spec.rb | 42 | ||||
-rw-r--r-- | spec/lib/sentry/client/issue_spec.rb | 4 |
3 files changed, 125 insertions, 5 deletions
diff --git a/spec/lib/gitlab/sidekiq_config/worker_spec.rb b/spec/lib/gitlab/sidekiq_config/worker_spec.rb new file mode 100644 index 00000000000..f2fe51abd5e --- /dev/null +++ b/spec/lib/gitlab/sidekiq_config/worker_spec.rb @@ -0,0 +1,84 @@ +# frozen_string_literal: true + +require 'fast_spec_helper' + +describe Gitlab::SidekiqConfig::Worker do + def worker_with_queue(queue) + described_class.new(double(queue: queue), ee: false) + end + + describe '#ee?' do + it 'returns the EE status set on creation' do + expect(described_class.new(double, ee: true)).to be_ee + expect(described_class.new(double, ee: false)).not_to be_ee + end + end + + describe '#==' do + def worker_with_yaml(yaml) + described_class.new(double, ee: false).tap do |worker| + allow(worker).to receive(:to_yaml).and_return(yaml) + end + end + + it 'defines two workers as equal if their YAML representations are equal' do + expect(worker_with_yaml('a')).to eq(worker_with_yaml('a')) + expect(worker_with_yaml('a')).not_to eq(worker_with_yaml('b')) + end + + it 'returns true when a worker is compared with its YAML representation' do + expect(worker_with_yaml('a')).to eq('a') + expect(worker_with_yaml(a: 1, b: 2)).to eq(a: 1, b: 2) + end + end + + describe 'delegations' do + [ + :feature_category_not_owned?, :get_feature_category, + :get_worker_resource_boundary, :latency_sensitive_worker?, :queue, + :worker_has_external_dependencies? + ].each do |meth| + it "delegates #{meth} to the worker class" do + worker = double + + expect(worker).to receive(meth) + + described_class.new(worker, ee: false).send(meth) + end + end + end + + describe 'sorting' do + it 'sorts queues with a namespace before those without a namespace' do + namespaced_worker = worker_with_queue('namespace:queue') + plain_worker = worker_with_queue('a_queue') + + expect([plain_worker, namespaced_worker].sort) + .to eq([namespaced_worker, plain_worker]) + end + + it 'sorts alphabetically by queue' do + workers = [ + worker_with_queue('namespace:a'), + worker_with_queue('namespace:b'), + worker_with_queue('other_namespace:a'), + worker_with_queue('other_namespace:b'), + worker_with_queue('a'), + worker_with_queue('b') + ] + + expect(workers.shuffle.sort).to eq(workers) + end + end + + describe 'YAML encoding' do + it 'encodes the worker in YAML as a string of the queue' do + worker_a = worker_with_queue('a') + worker_b = worker_with_queue('b') + + expect(YAML.dump(worker_a)).to eq(YAML.dump('a')) + expect(YAML.dump([worker_a, worker_b])) + .to eq(YAML.dump(%w[a b])) + end + end +end diff --git a/spec/lib/gitlab/sidekiq_config_spec.rb b/spec/lib/gitlab/sidekiq_config_spec.rb index 49efbac160a..39bb149cf73 100644 --- a/spec/lib/gitlab/sidekiq_config_spec.rb +++ b/spec/lib/gitlab/sidekiq_config_spec.rb @@ -5,10 +5,10 @@ require 'spec_helper' describe Gitlab::SidekiqConfig do describe '.workers' do it 'includes all workers' do - workers = described_class.workers + worker_classes = described_class.workers.map(&:klass) - expect(workers).to include(PostReceive) - expect(workers).to include(MergeWorker) + expect(worker_classes).to include(PostReceive) + expect(worker_classes).to include(MergeWorker) end end @@ -44,4 +44,40 @@ describe Gitlab::SidekiqConfig do expect(queues).to include('unknown') end end + + 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 + before do + workers = [ + PostReceive, + MergeWorker, + ProcessCommitWorker + ].map { |worker| described_class::Worker.new(worker, ee: false) } + + allow(described_class).to receive(:workers).and_return(workers) + allow(Gitlab).to receive(:ee?).and_return(false) + end + + it 'returns true if the YAML file does not match the application code' do + allow(File).to receive(:read) + .with(described_class::FOSS_QUEUE_CONFIG_PATH) + .and_return(YAML.dump(%w[post_receive merge])) + + expect(described_class.all_queues_yml_outdated?).to be(true) + end + + it 'returns false if the YAML file matches the application code' do + allow(File).to receive(:read) + .with(described_class::FOSS_QUEUE_CONFIG_PATH) + .and_return(YAML.dump(%w[merge post_receive process_commit])) + + expect(described_class.all_queues_yml_outdated?).to be(false) + end + end end diff --git a/spec/lib/sentry/client/issue_spec.rb b/spec/lib/sentry/client/issue_spec.rb index 061ebcfdc06..2762c5b5cb9 100644 --- a/spec/lib/sentry/client/issue_spec.rb +++ b/spec/lib/sentry/client/issue_spec.rb @@ -8,7 +8,7 @@ describe Sentry::Client::Issue do let(:token) { 'test-token' } let(:sentry_url) { 'https://sentrytest.gitlab.com/api/0' } let(:client) { Sentry::Client.new(sentry_url, token) } - let(:issue_id) { 503504 } + let(:issue_id) { 11 } describe '#list_issues' do shared_examples 'issues have correct return type' do |klass| @@ -243,7 +243,7 @@ describe Sentry::Client::Issue do end it 'has a correct external URL' do - expect(subject.external_url).to eq('https://sentrytest.gitlab.com/api/0/issues/503504') + expect(subject.external_url).to eq('https://sentrytest.gitlab.com/api/0/issues/11') end it 'issue has a correct external base url' do |