diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-24 18:09:00 +0000 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2020-01-24 18:09:00 +0000 |
commit | 411cc77938f99b495e0fe802705d275a28e939ef (patch) | |
tree | 97770ec9904daeaaa1f7546b191d23b0a642da47 /spec/lib/gitlab | |
parent | 3e36f70be4bd74a412b2ea1286090b54803a8c20 (diff) | |
download | gitlab-ce-411cc77938f99b495e0fe802705d275a28e939ef.tar.gz |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/lib/gitlab')
-rw-r--r-- | spec/lib/gitlab/gitaly_client_spec.rb | 59 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/import_failure_service_spec.rb | 23 | ||||
-rw-r--r-- | spec/lib/gitlab/import_export/project_tree_restorer_spec.rb | 52 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_config/worker_spec.rb | 45 | ||||
-rw-r--r-- | spec/lib/gitlab/sidekiq_config_spec.rb | 60 |
5 files changed, 220 insertions, 19 deletions
diff --git a/spec/lib/gitlab/gitaly_client_spec.rb b/spec/lib/gitlab/gitaly_client_spec.rb index ebf56c0ae66..b03c1feb429 100644 --- a/spec/lib/gitlab/gitaly_client_spec.rb +++ b/spec/lib/gitlab/gitaly_client_spec.rb @@ -52,7 +52,7 @@ describe Gitlab::GitalyClient do end describe '.filesystem_id' do - it 'returns an empty string when the storage is not found in the response' do + it 'returns an empty string when the relevant storage status is not found in the response' do response = double("response") allow(response).to receive(:storage_statuses).and_return([]) allow_next_instance_of(Gitlab::GitalyClient::ServerService) do |instance| @@ -63,6 +63,63 @@ describe Gitlab::GitalyClient do end end + context 'when the relevant storage status is not found' do + before do + response = double('response') + allow(response).to receive(:storage_statuses).and_return([]) + allow_next_instance_of(Gitlab::GitalyClient::ServerService) do |instance| + allow(instance).to receive(:disk_statistics).and_return(response) + expect(instance).to receive(:storage_disk_statistics) + end + end + + describe '.filesystem_disk_available' do + it 'returns nil when the relevant storage status is not found in the response' do + expect(described_class.filesystem_disk_available('default')).to eq(nil) + end + end + + describe '.filesystem_disk_used' do + it 'returns nil when the relevant storage status is not found in the response' do + expect(described_class.filesystem_disk_used('default')).to eq(nil) + end + end + end + + context 'when the relevant storage status is found' do + let(:disk_available) { 42 } + let(:disk_used) { 42 } + let(:storage_status) { double('storage_status') } + + before do + allow(storage_status).to receive(:storage_name).and_return('default') + allow(storage_status).to receive(:used).and_return(disk_used) + allow(storage_status).to receive(:available).and_return(disk_available) + response = double('response') + allow(response).to receive(:storage_statuses).and_return([storage_status]) + allow_next_instance_of(Gitlab::GitalyClient::ServerService) do |instance| + allow(instance).to receive(:disk_statistics).and_return(response) + end + expect_next_instance_of(Gitlab::GitalyClient::ServerService) do |instance| + expect(instance).to receive(:storage_disk_statistics).and_return(storage_status) + end + end + + describe '.filesystem_disk_available' do + it 'returns disk available when the relevant storage status is found in the response' do + expect(storage_status).to receive(:available) + expect(described_class.filesystem_disk_available('default')).to eq(disk_available) + end + end + + describe '.filesystem_disk_used' do + it 'returns disk used when the relevant storage status is found in the response' do + expect(storage_status).to receive(:used) + expect(described_class.filesystem_disk_used('default')).to eq(disk_used) + end + end + end + describe '.stub_class' do it 'returns the gRPC health check stub' do expect(described_class.stub_class(:health_check)).to eq(::Grpc::Health::V1::Health::Stub) diff --git a/spec/lib/gitlab/import_export/import_failure_service_spec.rb b/spec/lib/gitlab/import_export/import_failure_service_spec.rb index 0351f88afdb..324328181e4 100644 --- a/spec/lib/gitlab/import_export/import_failure_service_spec.rb +++ b/spec/lib/gitlab/import_export/import_failure_service_spec.rb @@ -6,6 +6,7 @@ describe Gitlab::ImportExport::ImportFailureService do let(:importable) { create(:project, :builds_enabled, :issues_disabled, name: 'project', path: 'project') } let(:label) { create(:label) } let(:subject) { described_class.new(importable) } + let(:action) { "save_relation" } let(:relation_key) { "labels" } let(:relation_index) { 0 } @@ -15,7 +16,12 @@ describe Gitlab::ImportExport::ImportFailureService do let(:correlation_id) { 'my-correlation-id' } let(:retry_count) { 2 } let(:log_import_failure) do - subject.log_import_failure(relation_key, relation_index, exception, retry_count) + subject.log_import_failure( + source: action, + relation_key: relation_key, + relation_index: relation_index, + exception: exception, + retry_count: retry_count) end before do @@ -44,7 +50,7 @@ describe Gitlab::ImportExport::ImportFailureService do describe '#with_retry' do let(:perform_retry) do - subject.with_retry(relation_key, relation_index) do + subject.with_retry(action: action, relation_key: relation_key, relation_index: relation_index) do label.save! end end @@ -60,7 +66,12 @@ describe Gitlab::ImportExport::ImportFailureService do end it 'retries and logs import failure once with correct params' do - expect(subject).to receive(:log_import_failure).with(relation_key, relation_index, instance_of(exception), 1).once + expect(subject).to receive(:log_import_failure).with( + source: action, + relation_key: relation_key, + relation_index: relation_index, + exception: instance_of(exception), + retry_count: 1).once perform_retry end @@ -85,7 +96,11 @@ describe Gitlab::ImportExport::ImportFailureService do maximum_retry_count.times do |index| retry_count = index + 1 - expect(subject).to receive(:log_import_failure).with(relation_key, relation_index, instance_of(exception), retry_count) + expect(subject).to receive(:log_import_failure).with( + source: action, relation_key: relation_key, + relation_index: relation_index, + exception: instance_of(exception), + retry_count: retry_count) end expect { perform_retry }.to raise_exception(exception) diff --git a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb index ac9a63e8414..25f70420cda 100644 --- a/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb +++ b/spec/lib/gitlab/import_export/project_tree_restorer_spec.rb @@ -498,6 +498,58 @@ describe Gitlab::ImportExport::ProjectTreeRestorer do end end + context 'when post import action throw non-retriable exception' do + let(:exception) { StandardError.new('post_import_error') } + + before do + setup_import_export_config('light') + expect(project) + .to receive(:merge_requests) + .and_raise(exception) + end + + it 'report post import error' do + expect(restored_project_json).to eq(false) + expect(shared.errors).to include('post_import_error') + end + end + + context 'when post import action throw retriable exception one time' do + let(:exception) { GRPC::DeadlineExceeded.new } + + before do + setup_import_export_config('light') + expect(project) + .to receive(:merge_requests) + .and_raise(exception) + expect(project) + .to receive(:merge_requests) + .and_call_original + expect(restored_project_json).to eq(true) + end + + it_behaves_like 'restores project successfully', + issues: 1, + labels: 2, + label_with_priorities: 'A project label', + milestones: 1, + first_issue_labels: 1, + services: 1, + import_failures: 1 + + it 'records the failures in the database' do + import_failure = ImportFailure.last + + expect(import_failure.project_id).to eq(project.id) + expect(import_failure.relation_key).to be_nil + expect(import_failure.relation_index).to be_nil + expect(import_failure.exception_class).to eq('GRPC::DeadlineExceeded') + expect(import_failure.exception_message).to be_present + expect(import_failure.correlation_id_value).not_to be_empty + expect(import_failure.created_at).to be_present + end + end + context 'when the project has overridden params in import data' do before do setup_import_export_config('light') diff --git a/spec/lib/gitlab/sidekiq_config/worker_spec.rb b/spec/lib/gitlab/sidekiq_config/worker_spec.rb index f2fe51abd5e..ba6760f38b5 100644 --- a/spec/lib/gitlab/sidekiq_config/worker_spec.rb +++ b/spec/lib/gitlab/sidekiq_config/worker_spec.rb @@ -3,8 +3,11 @@ require 'fast_spec_helper' describe Gitlab::SidekiqConfig::Worker do - def worker_with_queue(queue) - described_class.new(double(queue: queue), ee: false) + def create_worker(queue:, weight: 0) + namespace = queue.include?(':') && queue.split(':').first + inner_worker = double(queue: queue, queue_namespace: namespace, get_weight: weight) + + described_class.new(inner_worker, ee: false) end describe '#ee?' do @@ -34,9 +37,9 @@ describe Gitlab::SidekiqConfig::Worker do describe 'delegations' do [ - :feature_category_not_owned?, :get_feature_category, + :feature_category_not_owned?, :get_feature_category, :get_weight, :get_worker_resource_boundary, :latency_sensitive_worker?, :queue, - :worker_has_external_dependencies? + :queue_namespace, :worker_has_external_dependencies? ].each do |meth| it "delegates #{meth} to the worker class" do worker = double @@ -50,8 +53,8 @@ describe Gitlab::SidekiqConfig::Worker do 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') + namespaced_worker = create_worker(queue: 'namespace:queue') + plain_worker = create_worker(queue: 'a_queue') expect([plain_worker, namespaced_worker].sort) .to eq([namespaced_worker, plain_worker]) @@ -59,12 +62,12 @@ describe Gitlab::SidekiqConfig::Worker do 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') + create_worker(queue: 'namespace:a'), + create_worker(queue: 'namespace:b'), + create_worker(queue: 'other_namespace:a'), + create_worker(queue: 'other_namespace:b'), + create_worker(queue: 'a'), + create_worker(queue: 'b') ] expect(workers.shuffle.sort).to eq(workers) @@ -73,12 +76,26 @@ describe Gitlab::SidekiqConfig::Worker do 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') + worker_a = create_worker(queue: 'a') + worker_b = create_worker(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 + + describe '#namespace_and_weight' do + it 'returns a namespace, weight pair for the worker' do + expect(create_worker(queue: 'namespace:a', weight: 2).namespace_and_weight) + .to eq(['namespace', 2]) + end + end + + describe '#queue_and_weight' do + it 'returns a queue, weight pair for the worker' do + expect(create_worker(queue: 'namespace:a', weight: 2).queue_and_weight) + .to eq(['namespace:a', 2]) + end + end end diff --git a/spec/lib/gitlab/sidekiq_config_spec.rb b/spec/lib/gitlab/sidekiq_config_spec.rb index 39bb149cf73..20690a35dc8 100644 --- a/spec/lib/gitlab/sidekiq_config_spec.rb +++ b/spec/lib/gitlab/sidekiq_config_spec.rb @@ -80,4 +80,64 @@ describe Gitlab::SidekiqConfig do expect(described_class.all_queues_yml_outdated?).to be(false) end end + + describe '.queues_for_sidekiq_queues_yml' do + before do + workers = [ + Namespaces::RootStatisticsWorker, + Namespaces::ScheduleAggregationWorker, + MergeWorker, + ProcessCommitWorker + ].map { |worker| described_class::Worker.new(worker, ee: false) } + + allow(described_class).to receive(:workers).and_return(workers) + end + + it 'returns queues and weights, aggregating namespaces with the same weight' do + expected_queues = [ + ['merge', 5], + ['process_commit', 3], + ['update_namespace_statistics', 1] + ] + + expect(described_class.queues_for_sidekiq_queues_yml).to eq(expected_queues) + end + end + + describe '.sidekiq_queues_yml_outdated?' do + before do + workers = [ + Namespaces::RootStatisticsWorker, + Namespaces::ScheduleAggregationWorker, + MergeWorker, + ProcessCommitWorker + ].map { |worker| described_class::Worker.new(worker, ee: false) } + + allow(described_class).to receive(:workers).and_return(workers) + end + + let(:expected_queues) do + [ + ['merge', 5], + ['process_commit', 3], + ['update_namespace_statistics', 1] + ] + end + + it 'returns true if the YAML file does not match the application code' do + allow(File).to receive(:read) + .with(described_class::SIDEKIQ_QUEUES_PATH) + .and_return(YAML.dump(queues: expected_queues.reverse)) + + expect(described_class.sidekiq_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::SIDEKIQ_QUEUES_PATH) + .and_return(YAML.dump(queues: expected_queues)) + + expect(described_class.sidekiq_queues_yml_outdated?).to be(false) + end + end end |