diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-28 21:26:46 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2023-04-28 21:26:46 +0300 |
commit | 5509e479900ee537980a126287c20327c41a61d6 (patch) | |
tree | 8272f06bd58b1518eca38975f95656ffc5497bd2 /spec/commands/sidekiq_cluster | |
parent | e0529f76a36026dc4bd51fbec1e5c52e7f3866e1 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/commands/sidekiq_cluster')
-rw-r--r-- | spec/commands/sidekiq_cluster/cli_spec.rb | 70 |
1 files changed, 58 insertions, 12 deletions
diff --git a/spec/commands/sidekiq_cluster/cli_spec.rb b/spec/commands/sidekiq_cluster/cli_spec.rb index 499432c2605..085be1ceac2 100644 --- a/spec/commands/sidekiq_cluster/cli_spec.rb +++ b/spec/commands/sidekiq_cluster/cli_spec.rb @@ -37,6 +37,8 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ allow(supervisor).to receive(:supervise) allow(Prometheus::CleanupMultiprocDirService).to receive(:new).and_return(metrics_cleanup_service) + + stub_config(sidekiq: { routing_rules: [] }) end around do |example| @@ -58,7 +60,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ context 'with arguments' do it 'starts the Sidekiq workers' do expect(Gitlab::SidekiqCluster).to receive(:start) - .with([['foo']], default_options) + .with([['foo'] + described_class::DEFAULT_QUEUES], default_options) .and_return([]) cli.run(%w(foo)) @@ -92,7 +94,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ it 'starts Sidekiq workers for all queues in all_queues.yml except the ones in argv' do expect(Gitlab::SidekiqConfig::CliMethods).to receive(:worker_queues).and_return(['baz']) expect(Gitlab::SidekiqCluster).to receive(:start) - .with([['baz']], default_options) + .with([['baz'] + described_class::DEFAULT_QUEUES], default_options) .and_return([]) cli.run(%w(foo -n)) @@ -101,9 +103,10 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ context 'with --max-concurrency flag' do it 'starts Sidekiq workers for specified queues with a max concurrency' do + expected_queues = [%w(foo bar baz), %w(solo)].each { |queues| queues.concat(described_class::DEFAULT_QUEUES) } expect(Gitlab::SidekiqConfig::CliMethods).to receive(:worker_queues).and_return(%w(foo bar baz)) expect(Gitlab::SidekiqCluster).to receive(:start) - .with([%w(foo bar baz), %w(solo)], default_options.merge(max_concurrency: 2)) + .with(expected_queues, default_options.merge(max_concurrency: 2)) .and_return([]) cli.run(%w(foo,bar,baz solo -m 2)) @@ -112,9 +115,10 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ context 'with --min-concurrency flag' do it 'starts Sidekiq workers for specified queues with a min concurrency' do + expected_queues = [%w(foo bar baz), %w(solo)].each { |queues| queues.concat(described_class::DEFAULT_QUEUES) } expect(Gitlab::SidekiqConfig::CliMethods).to receive(:worker_queues).and_return(%w(foo bar baz)) expect(Gitlab::SidekiqCluster).to receive(:start) - .with([%w(foo bar baz), %w(solo)], default_options.merge(min_concurrency: 2)) + .with(expected_queues, default_options.merge(min_concurrency: 2)) .and_return([]) cli.run(%w(foo,bar,baz solo --min-concurrency 2)) @@ -124,7 +128,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ context 'with --timeout flag' do it 'when given', 'starts Sidekiq workers with given timeout' do expect(Gitlab::SidekiqCluster).to receive(:start) - .with([['foo']], default_options.merge(timeout: 10)) + .with([['foo'] + described_class::DEFAULT_QUEUES], default_options.merge(timeout: 10)) .and_return([]) cli.run(%w(foo --timeout 10)) @@ -132,7 +136,8 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ it 'when not given', 'starts Sidekiq workers with default timeout' do expect(Gitlab::SidekiqCluster).to receive(:start) - .with([['foo']], default_options.merge(timeout: Gitlab::SidekiqCluster::DEFAULT_SOFT_TIMEOUT_SECONDS)) + .with([['foo'] + described_class::DEFAULT_QUEUES], default_options.merge(timeout: + Gitlab::SidekiqCluster::DEFAULT_SOFT_TIMEOUT_SECONDS)) .and_return([]) cli.run(%w(foo)) @@ -146,8 +151,10 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ it 'prints out a list of queues in alphabetical order' do expected_queues = [ + 'default', 'epics:epics_update_epics_dates', 'epics_new_epic_issue', + 'mailers', 'new_epic', 'todos_destroyer:todos_destroyer_confidential_epic' ] @@ -164,7 +171,8 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ it 'starts Sidekiq workers for all queues in all_queues.yml with a namespace in argv' do expect(Gitlab::SidekiqConfig::CliMethods).to receive(:worker_queues).and_return(['cronjob:foo', 'cronjob:bar']) expect(Gitlab::SidekiqCluster).to receive(:start) - .with([['cronjob', 'cronjob:foo', 'cronjob:bar']], default_options) + .with([['cronjob', 'cronjob:foo', 'cronjob:bar'] + + described_class::DEFAULT_QUEUES], default_options) .and_return([]) cli.run(%w(cronjob)) @@ -202,7 +210,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ 'CI and SCM queues' => { query: 'feature_category=continuous_integration|feature_category=source_code_management', included_queues: %w(pipeline_default:ci_drop_pipeline merge), - excluded_queues: %w(mailers) + excluded_queues: %w() } } end @@ -213,6 +221,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ expect(opts).to eq(default_options) expect(queues.first).to include(*included_queues) expect(queues.first).not_to include(*excluded_queues) + expect(queues.first).to include(*described_class::DEFAULT_QUEUES) [] end @@ -225,6 +234,7 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ expect(opts).to eq(default_options) expect(queues.first).not_to include(*included_queues) expect(queues.first).to include(*excluded_queues) + expect(queues.first).to include(*described_class::DEFAULT_QUEUES) [] end @@ -237,13 +247,15 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ expected_workers = if Gitlab.ee? [ - %w[cronjob:clusters_integrations_check_prometheus_health incident_management_close_incident status_page_publish], - %w[bulk_imports_pipeline bulk_imports_relation_export project_export projects_import_export_parallel_project_export projects_import_export_relation_export repository_import project_template_export] + %w[cronjob:clusters_integrations_check_prometheus_health incident_management_close_incident status_page_publish] + described_class::DEFAULT_QUEUES, + %w[bulk_imports_pipeline bulk_imports_relation_export project_export projects_import_export_parallel_project_export projects_import_export_relation_export repository_import project_template_export] + + described_class::DEFAULT_QUEUES ] else [ - %w[cronjob:clusters_integrations_check_prometheus_health incident_management_close_incident], - %w[bulk_imports_pipeline bulk_imports_relation_export project_export projects_import_export_parallel_project_export projects_import_export_relation_export repository_import] + %w[cronjob:clusters_integrations_check_prometheus_health incident_management_close_incident] + described_class::DEFAULT_QUEUES, + %w[bulk_imports_pipeline bulk_imports_relation_export project_export projects_import_export_parallel_project_export projects_import_export_relation_export repository_import] + + described_class::DEFAULT_QUEUES ] end @@ -281,6 +293,40 @@ RSpec.describe Gitlab::SidekiqCluster::CLI, feature_category: :gitlab_cli, stub_ .to raise_error(Gitlab::SidekiqConfig::WorkerMatcher::QueryError) end end + + context "with routing rules specified" do + before do + stub_config(sidekiq: { routing_rules: [['resource_boundary=cpu', 'foo']] }) + end + + it "starts Sidekiq workers only for given queues without any additional DEFAULT_QUEUES" do + expect(Gitlab::SidekiqCluster).to receive(:start) + .with([['foo']], default_options) + .and_return([]) + + cli.run(%w(foo)) + end + end + + context "with sidekiq settings not specified" do + before do + stub_config(sidekiq: nil) + end + + it "does not throw an error" do + allow(Gitlab::SidekiqCluster).to receive(:start).and_return([]) + + expect { cli.run(%w(foo)) }.not_to raise_error + end + + it "starts Sidekiq workers with given queues, and additional default and mailers queues (DEFAULT_QUEUES)" do + expect(Gitlab::SidekiqCluster).to receive(:start) + .with([['foo'] + described_class::DEFAULT_QUEUES], default_options) + .and_return([]) + + cli.run(%w(foo)) + end + end end context 'metrics server' do |