diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 12:08:43 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-02-14 12:08:43 +0300 |
commit | 733befe96ad19f5a02e442c4a9cc8059d3aabbda (patch) | |
tree | dcabd344df040e536a242edc4e3121fb3efca142 /spec/lib/gitlab/sidekiq_config | |
parent | 10213bf3b26c3c21f7683471d35d1cd052c41e9c (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab/sidekiq_config')
-rw-r--r-- | spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb | 111 |
1 files changed, 106 insertions, 5 deletions
diff --git a/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb b/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb index 60d946db744..e6d0055df64 100644 --- a/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb +++ b/spec/lib/gitlab/sidekiq_config/cli_methods_spec.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require 'fast_spec_helper' +require 'rspec-parameterized' describe Gitlab::SidekiqConfig::CliMethods do let(:dummy_root) { '/tmp/' } @@ -82,7 +83,7 @@ describe Gitlab::SidekiqConfig::CliMethods do end describe '.expand_queues' do - let(:all_queues) do + let(:worker_queues) do ['cronjob:stuck_import_jobs', 'cronjob:stuck_merge_jobs', 'post_receive'] end @@ -92,25 +93,125 @@ describe Gitlab::SidekiqConfig::CliMethods do expect(described_class.expand_queues(['cronjob'])) .to contain_exactly('cronjob') - allow(described_class).to receive(:worker_queues).and_return(all_queues) + allow(described_class).to receive(:worker_queues).and_return(worker_queues) expect(described_class.expand_queues(['cronjob'])) .to contain_exactly('cronjob', 'cronjob:stuck_import_jobs', 'cronjob:stuck_merge_jobs') end it 'expands queue namespaces to concrete queue names' do - expect(described_class.expand_queues(['cronjob'], all_queues)) + expect(described_class.expand_queues(['cronjob'], worker_queues)) .to contain_exactly('cronjob', 'cronjob:stuck_import_jobs', 'cronjob:stuck_merge_jobs') end it 'lets concrete queue names pass through' do - expect(described_class.expand_queues(['post_receive'], all_queues)) + expect(described_class.expand_queues(['post_receive'], worker_queues)) .to contain_exactly('post_receive') end it 'lets unknown queues pass through' do - expect(described_class.expand_queues(['unknown'], all_queues)) + expect(described_class.expand_queues(['unknown'], worker_queues)) .to contain_exactly('unknown') end end + + describe '.query_workers' do + using RSpec::Parameterized::TableSyntax + + let(:queues) do + [ + { + name: 'a', + feature_category: :category_a, + has_external_dependencies: false, + latency_sensitive: false, + resource_boundary: :cpu + }, + { + name: 'a_2', + feature_category: :category_a, + has_external_dependencies: false, + latency_sensitive: true, + resource_boundary: :none + }, + { + name: 'b', + feature_category: :category_b, + has_external_dependencies: true, + latency_sensitive: true, + resource_boundary: :memory + }, + { + name: 'c', + feature_category: :category_c, + has_external_dependencies: false, + latency_sensitive: false, + resource_boundary: :memory + } + ] + end + + context 'with valid input' do + where(:query, :selected_queues) do + # feature_category + 'feature_category=category_a' | %w(a a_2) + 'feature_category=category_a,category_c' | %w(a a_2 c) + 'feature_category=category_a|feature_category=category_c' | %w(a a_2 c) + 'feature_category!=category_a' | %w(b c) + + # has_external_dependencies + 'has_external_dependencies=true' | %w(b) + 'has_external_dependencies=false' | %w(a a_2 c) + 'has_external_dependencies=true,false' | %w(a a_2 b c) + 'has_external_dependencies=true|has_external_dependencies=false' | %w(a a_2 b c) + 'has_external_dependencies!=true' | %w(a a_2 c) + + # latency_sensitive + 'latency_sensitive=true' | %w(a_2 b) + 'latency_sensitive=false' | %w(a c) + 'latency_sensitive=true,false' | %w(a a_2 b c) + 'latency_sensitive=true|latency_sensitive=false' | %w(a a_2 b c) + 'latency_sensitive!=true' | %w(a c) + + # name + 'name=a' | %w(a) + 'name=a,b' | %w(a b) + 'name=a,a_2|name=b' | %w(a a_2 b) + 'name!=a,a_2' | %w(b c) + + # resource_boundary + 'resource_boundary=memory' | %w(b c) + 'resource_boundary=memory,cpu' | %w(a b c) + 'resource_boundary=memory|resource_boundary=cpu' | %w(a b c) + 'resource_boundary!=memory,cpu' | %w(a_2) + + # combinations + 'feature_category=category_a&latency_sensitive=true' | %w(a_2) + 'feature_category=category_a&latency_sensitive=true|feature_category=category_c' | %w(a_2 c) + end + + with_them do + it do + expect(described_class.query_workers(query, queues)) + .to match_array(selected_queues) + end + end + end + + context 'with invalid input' do + where(:query, :error) do + 'feature_category="category_a"' | described_class::InvalidTerm + 'feature_category=' | described_class::InvalidTerm + 'feature_category~category_a' | described_class::InvalidTerm + 'worker_name=a' | described_class::UnknownPredicate + end + + with_them do + it do + expect { described_class.query_workers(query, queues) } + .to raise_error(error) + end + end + end + end end |