diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-20 12:16:11 +0300 |
commit | edaa33dee2ff2f7ea3fac488d41558eb5f86d68c (patch) | |
tree | 11f143effbfeba52329fb7afbd05e6e2a3790241 /spec/commands/sidekiq_cluster/cli_spec.rb | |
parent | d8a5691316400a0f7ec4f83832698f1988eb27c1 (diff) |
Add latest changes from gitlab-org/gitlab@14-7-stable-eev14.7.0-rc42
Diffstat (limited to 'spec/commands/sidekiq_cluster/cli_spec.rb')
-rw-r--r-- | spec/commands/sidekiq_cluster/cli_spec.rb | 122 |
1 files changed, 77 insertions, 45 deletions
diff --git a/spec/commands/sidekiq_cluster/cli_spec.rb b/spec/commands/sidekiq_cluster/cli_spec.rb index 148b8720740..d7488e8d965 100644 --- a/spec/commands/sidekiq_cluster/cli_spec.rb +++ b/spec/commands/sidekiq_cluster/cli_spec.rb @@ -5,7 +5,7 @@ require 'rspec-parameterized' require_relative '../../../sidekiq_cluster/cli' -RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath +RSpec.describe Gitlab::SidekiqCluster::CLI, stubbing_settings_source: true do # rubocop:disable RSpec/FilePath let(:cli) { described_class.new('/dev/null') } let(:timeout) { Gitlab::SidekiqCluster::DEFAULT_SOFT_TIMEOUT_SECONDS } let(:default_options) do @@ -16,19 +16,39 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath let(:sidekiq_exporter_port) { '3807' } let(:sidekiq_health_checks_port) { '3807' } - before do - stub_env('RAILS_ENV', 'test') - stub_config( - monitoring: { - sidekiq_exporter: { - enabled: sidekiq_exporter_enabled, - port: sidekiq_exporter_port - }, - sidekiq_health_checks: { - port: sidekiq_health_checks_port + let(:config_file) { Tempfile.new('gitlab.yml') } + let(:config) do + { + 'test' => { + 'monitoring' => { + 'sidekiq_exporter' => { + 'address' => 'localhost', + 'enabled' => sidekiq_exporter_enabled, + 'port' => sidekiq_exporter_port + }, + 'sidekiq_health_checks' => { + 'address' => 'localhost', + 'enabled' => sidekiq_exporter_enabled, + 'port' => sidekiq_health_checks_port + } } } - ) + } + end + + before do + stub_env('RAILS_ENV', 'test') + + config_file.write(YAML.dump(config)) + config_file.close + + allow(::Settings).to receive(:source).and_return(config_file.path) + + ::Settings.reload! + end + + after do + config_file.unlink end describe '#run' do @@ -272,16 +292,9 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath context 'starting the server' do context 'without --dryrun' do context 'when there are no sidekiq_health_checks settings set' do - before do - stub_config( - monitoring: { - sidekiq_exporter: { - enabled: true, - port: sidekiq_exporter_port - } - } - ) + let(:sidekiq_exporter_enabled) { true } + before do allow(Gitlab::SidekiqCluster).to receive(:start) allow(cli).to receive(:write_pid) allow(cli).to receive(:trap_signals) @@ -293,25 +306,42 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath cli.run(%w(foo)) end - - it 'rescues Settingslogic::MissingSetting' do - expect { cli.run(%w(foo)) }.not_to raise_error(Settingslogic::MissingSetting) - end end context 'when the sidekiq_exporter.port setting is not set' do + let(:sidekiq_exporter_enabled) { true } + before do - stub_config( - monitoring: { - sidekiq_exporter: { - enabled: true - }, - sidekiq_health_checks: { - port: sidekiq_health_checks_port + allow(Gitlab::SidekiqCluster).to receive(:start) + allow(cli).to receive(:write_pid) + allow(cli).to receive(:trap_signals) + allow(cli).to receive(:start_loop) + end + + it 'does not start a sidekiq metrics server' do + expect(MetricsServer).not_to receive(:spawn) + + cli.run(%w(foo)) + end + end + + context 'when sidekiq_exporter.enabled setting is not set' do + let(:config) do + { + 'test' => { + 'monitoring' => { + 'sidekiq_exporter' => {}, + 'sidekiq_health_checks' => { + 'address' => 'localhost', + 'enabled' => sidekiq_exporter_enabled, + 'port' => sidekiq_health_checks_port + } } } - ) + } + end + before do allow(Gitlab::SidekiqCluster).to receive(:start) allow(cli).to receive(:write_pid) allow(cli).to receive(:trap_signals) @@ -323,23 +353,21 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath cli.run(%w(foo)) end - - it 'rescues Settingslogic::MissingSetting' do - expect { cli.run(%w(foo)) }.not_to raise_error(Settingslogic::MissingSetting) - end end - context 'when sidekiq_exporter.enabled setting is not set' do - before do - stub_config( - monitoring: { - sidekiq_exporter: {}, - sidekiq_health_checks: { - port: sidekiq_health_checks_port + context 'with a blank sidekiq_exporter setting' do + let(:config) do + { + 'test' => { + 'monitoring' => { + 'sidekiq_exporter' => nil, + 'sidekiq_health_checks' => nil } } - ) + } + end + before do allow(Gitlab::SidekiqCluster).to receive(:start) allow(cli).to receive(:write_pid) allow(cli).to receive(:trap_signals) @@ -351,6 +379,10 @@ RSpec.describe Gitlab::SidekiqCluster::CLI do # rubocop:disable RSpec/FilePath cli.run(%w(foo)) end + + it 'does not throw an error' do + expect { cli.run(%w(foo)) }.not_to raise_error + end end context 'with valid settings' do |