diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-07 00:12:16 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-10-07 00:12:16 +0300 |
commit | 87598f1576cc7b3e1071a83d70778a51009b853b (patch) | |
tree | 42a1e678a3f9abf870d1cc88ecf536375f889b12 /spec/workers/gitlab/github_import | |
parent | 30e5ae4c2b9c1674dc222e4bde0daa3f9795782e (diff) |
Add latest changes from gitlab-org/gitlab@master
Diffstat (limited to 'spec/workers/gitlab/github_import')
4 files changed, 72 insertions, 38 deletions
diff --git a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb index 132fe1dc618..dd976eef28b 100644 --- a/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/finish_import_worker_spec.rb @@ -7,39 +7,27 @@ RSpec.describe Gitlab::GithubImport::Stage::FinishImportWorker do let(:worker) { described_class.new } describe '#perform' do - it 'marks the import as finished' do + it 'marks the import as finished and reports import statistics' do expect(project).to receive(:after_import) - expect(worker).to receive(:report_import_time).with(project) - - worker.import(double(:client), project) - end - end - - describe '#report_import_time' do - it 'reports the total import time' do - expect(worker.histogram) - .to receive(:observe) - .with({ project: project.path_with_namespace }, a_kind_of(Numeric)) - .and_call_original - - expect(worker.counter) - .to receive(:increment) - .and_call_original + expect_next_instance_of(Gitlab::Import::Metrics) do |instance| + expect(instance).to receive(:track_finished_import) + expect(instance).to receive(:duration).and_return(3.005) + end expect(Gitlab::GithubImport::Logger) .to receive(:info) - .with( - message: 'GitHub project import finished', - import_stage: 'Gitlab::GithubImport::Stage::FinishImportWorker', - object_counts: { - 'fetched' => {}, - 'imported' => {} - }, - project_id: project.id, - duration_s: a_kind_of(Numeric) - ) + .with( + message: 'GitHub project import finished', + import_stage: 'Gitlab::GithubImport::Stage::FinishImportWorker', + object_counts: { + 'fetched' => {}, + 'imported' => {} + }, + project_id: project.id, + duration_s: 3.01 + ) - worker.report_import_time(project) + worker.import(double(:client), project) end end end diff --git a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb index f68d0838501..7b2218b1725 100644 --- a/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_base_data_worker_spec.rb @@ -3,15 +3,15 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do - let(:project) { create(:project) } - let(:import_state) { create(:import_state, project: project) } + let_it_be(:project) { create(:project) } + let_it_be(:import_state) { create(:import_state, project: project) } + let(:worker) { described_class.new } + let(:importer) { double(:importer) } + let(:client) { double(:client) } describe '#import' do it 'imports the base data of a project' do - importer = double(:importer) - client = double(:client) - described_class::IMPORTERS.each do |klass| expect(klass) .to receive(:new) @@ -29,5 +29,23 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportBaseDataWorker do worker.import(client, project) end + + it 'raises an error' do + exception = StandardError.new('_some_error_') + + expect_next_instance_of(Gitlab::GithubImport::Importer::LabelsImporter) do |importer| + expect(importer).to receive(:execute).and_raise(exception) + end + expect(Gitlab::Import::ImportFailureService).to receive(:track) + .with( + project_id: project.id, + exception: exception, + error_source: described_class.name, + fail_import: true, + metrics: true + ).and_call_original + + expect { worker.import(client, project) }.to raise_error(StandardError) + end end end diff --git a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb index 29578f9bf37..b18b5ce64d1 100644 --- a/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_pull_requests_worker_spec.rb @@ -3,14 +3,15 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do - let(:project) { create(:project) } - let(:import_state) { create(:import_state, project: project) } + let_it_be(:project) { create(:project) } + let_it_be(:import_state) { create(:import_state, project: project) } + let(:worker) { described_class.new } + let(:importer) { double(:importer) } + let(:client) { double(:client) } describe '#import' do it 'imports all the pull requests' do - importer = double(:importer) - client = double(:client) waiter = Gitlab::JobWaiter.new(2, '123') expect(Gitlab::GithubImport::Importer::PullRequestsImporter) @@ -32,4 +33,22 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportPullRequestsWorker do worker.import(client, project) end end + + it 'raises an error' do + exception = StandardError.new('_some_error_') + + expect_next_instance_of(Gitlab::GithubImport::Importer::PullRequestsImporter) do |importer| + expect(importer).to receive(:execute).and_raise(exception) + end + expect(Gitlab::Import::ImportFailureService).to receive(:track) + .with( + project_id: project.id, + exception: exception, + error_source: described_class.name, + fail_import: true, + metrics: true + ).and_call_original + + expect { worker.import(client, project) }.to raise_error(StandardError) + end end diff --git a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb index 875fc082975..582cb76a6cd 100644 --- a/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb +++ b/spec/workers/gitlab/github_import/stage/import_repository_worker_spec.rb @@ -3,7 +3,7 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do - let(:project) { double(:project, id: 4) } + let_it_be(:project) { create(:project, :import_started) } let(:worker) { described_class.new } @@ -43,6 +43,15 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do expect(instance).to receive(:execute).and_raise(exception_class) end + expect(Gitlab::Import::ImportFailureService).to receive(:track) + .with( + project_id: project.id, + exception: exception_class, + error_source: described_class.name, + fail_import: true, + metrics: true + ).and_call_original + expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) .not_to receive(:perform_async) |