diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-04 18:15:09 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2022-01-04 18:15:09 +0300 |
commit | d19a19ce85fe06bef4cea7c0f4415979086b4305 (patch) | |
tree | 51d6a1ce734ddac0c37466f9a6a21409fea7ec96 /spec | |
parent | 76893705a1df96909da44ab3c99816fd12129206 (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec')
-rw-r--r-- | spec/commands/sidekiq_cluster/cli_spec.rb | 122 | ||||
-rw-r--r-- | spec/factories/ci/builds.rb | 4 | ||||
-rw-r--r-- | spec/models/ci/build_spec.rb | 30 | ||||
-rw-r--r-- | spec/spec_helper.rb | 8 |
4 files changed, 116 insertions, 48 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 diff --git a/spec/factories/ci/builds.rb b/spec/factories/ci/builds.rb index 98023334894..d1a9ace605a 100644 --- a/spec/factories/ci/builds.rb +++ b/spec/factories/ci/builds.rb @@ -335,6 +335,10 @@ FactoryBot.define do running runner factory: :ci_runner + + after(:create) do |build| + build.create_runtime_metadata! + end end trait :artifacts do diff --git a/spec/models/ci/build_spec.rb b/spec/models/ci/build_spec.rb index 5653ef275e9..c4f4e2cb2dc 100644 --- a/spec/models/ci/build_spec.rb +++ b/spec/models/ci/build_spec.rb @@ -5427,7 +5427,8 @@ RSpec.describe Ci::Build do describe '#doom!' do subject { build.doom! } - let_it_be(:build) { create(:ci_build, :queued) } + let(:traits) { [] } + let(:build) { create(:ci_build, *traits, pipeline: pipeline) } it 'updates status and failure_reason', :aggregate_failures do subject @@ -5436,10 +5437,33 @@ RSpec.describe Ci::Build do expect(build.failure_reason).to eq("data_integrity_failure") end - it 'drops associated pending build' do + it 'logs a message' do + expect(Gitlab::AppLogger) + .to receive(:info) + .with(a_hash_including(message: 'Build doomed', class: build.class.name, build_id: build.id)) + .and_call_original + subject + end + + context 'with queued builds' do + let(:traits) { [:queued] } + + it 'drops associated pending build' do + subject + + expect(build.reload.queuing_entry).not_to be_present + end + end - expect(build.reload.queuing_entry).not_to be_present + context 'with running builds' do + let(:traits) { [:picked] } + + it 'drops associated runtime metadata' do + subject + + expect(build.reload.runtime_metadata).not_to be_present + end end end diff --git a/spec/spec_helper.rb b/spec/spec_helper.rb index c497f8245fe..a2f4236b3ed 100644 --- a/spec/spec_helper.rb +++ b/spec/spec_helper.rb @@ -463,6 +463,14 @@ RSpec.configure do |config| $stdout = STDOUT end + config.around(:each, stubbing_settings_source: true) do |example| + original_instance = ::Settings.instance_variable_get(:@instance) + + example.run + + ::Settings.instance_variable_set(:@instance, original_instance) + end + config.disable_monkey_patching! end |