Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
Diffstat (limited to 'spec/workers/concerns/gitlab')
-rw-r--r--spec/workers/concerns/gitlab/github_import/object_importer_spec.rb67
-rw-r--r--spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb122
2 files changed, 75 insertions, 114 deletions
diff --git a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
index 27e1077b138..b2bc502d156 100644
--- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb
@@ -16,7 +16,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
end
def representation_class
- MockRepresantation
+ MockRepresentation
end
end.new
end
@@ -62,7 +62,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
let(:stubbed_representation) { representation_class }
before do
- stub_const('MockRepresantation', stubbed_representation)
+ stub_const('MockRepresentation', stubbed_representation)
end
describe '#import', :clean_gitlab_redis_cache do
@@ -76,7 +76,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
it 'imports the object' do
expect(importer_class)
.to receive(:new)
- .with(instance_of(MockRepresantation), project, client)
+ .with(instance_of(MockRepresentation), project, client)
.and_return(importer_instance)
expect(importer_instance)
@@ -86,7 +86,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
.to receive(:info)
.with(
{
- github_identifiers: github_identifiers,
+ external_identifiers: github_identifiers,
message: 'starting importer',
project_id: project.id,
importer: 'klass_name'
@@ -97,7 +97,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
.to receive(:info)
.with(
{
- github_identifiers: github_identifiers,
+ external_identifiers: github_identifiers,
message: 'importer finished',
project_id: project.id,
importer: 'klass_name'
@@ -123,7 +123,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
.to receive(:info)
.with(
{
- github_identifiers: nil,
+ external_identifiers: nil,
message: 'Project import is no longer running. Stopping worker.',
project_id: project.id,
importer: 'klass_name',
@@ -135,12 +135,13 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
end
it 'logs error when the import fails' do
+ exception = StandardError.new('some error')
+
expect(importer_class)
.to receive(:new)
- .with(instance_of(MockRepresantation), project, client)
+ .with(instance_of(MockRepresentation), project, client)
.and_return(importer_instance)
- exception = StandardError.new('some error')
expect(importer_instance)
.to receive(:execute)
.and_raise(exception)
@@ -149,20 +150,46 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
.to receive(:info)
.with(
{
- github_identifiers: github_identifiers,
message: 'starting importer',
+ external_identifiers: github_identifiers,
project_id: project.id,
importer: 'klass_name'
}
)
+ expect(Gitlab::Import::Logger)
+ .to receive(:error)
+ .with(
+ {
+ message: 'importer failed',
+ 'exception.message': 'some error',
+ import_type: project.import_type,
+ project_id: project.id,
+ source: 'klass_name',
+ external_identifiers: github_identifiers
+ }
+ )
+
+ expect(Gitlab::ErrorTracking)
+ .to receive(:track_exception)
+ .with(
+ exception,
+ {
+ import_type: project.import_type,
+ project_id: project.id,
+ source: 'klass_name',
+ external_identifiers: github_identifiers
+ }
+ )
+
expect(Gitlab::Import::ImportFailureService)
.to receive(:track)
.with(
project_id: project.id,
exception: exception,
error_source: 'klass_name',
- fail_import: false
+ fail_import: false,
+ external_identifiers: github_identifiers
)
.and_call_original
@@ -188,7 +215,8 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
project_id: project.id,
exception: a_kind_of(NoMethodError),
error_source: 'klass_name',
- fail_import: true
+ fail_import: true,
+ external_identifiers: { object_type: 'dummy' }
)
.and_call_original
@@ -203,7 +231,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
before do
expect(importer_class)
.to receive(:new)
- .with(instance_of(MockRepresantation), project, client)
+ .with(instance_of(MockRepresentation), project, client)
.and_return(importer_instance)
expect(importer_instance)
@@ -216,7 +244,7 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
.to receive(:info)
.with(
{
- github_identifiers: github_identifiers,
+ external_identifiers: github_identifiers,
message: 'starting importer',
project_id: project.id,
importer: 'klass_name'
@@ -229,7 +257,8 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
project_id: project.id,
exception: exception,
error_source: 'klass_name',
- fail_import: false
+ fail_import: false,
+ external_identifiers: github_identifiers
)
.and_call_original
@@ -296,15 +325,5 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, featur
sidekiq_retries_exhausted
end
end
-
- it 'updates external_identifiers of the correct failure' do
- failure_1, failure_2 = create_list(:import_failure, 2, project: project)
- failure_2.update_column(:correlation_id_value, correlation_id)
-
- sidekiq_retries_exhausted
-
- expect(failure_1.reload.external_identifiers).to be_empty
- expect(failure_2.reload.external_identifiers).to eq(github_identifiers.with_indifferent_access)
- end
end
end
diff --git a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
index f65a8cd0d3c..c8f7427d5ae 100644
--- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
+++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb
@@ -92,106 +92,48 @@ RSpec.describe Gitlab::GithubImport::StageMethods, feature_category: :importers
worker.perform(project.id)
end
- context 'when abort_on_failure is false' do
- it 'logs error when import fails' do
- exception = StandardError.new('some error')
+ it 'logs error when import fails' do
+ exception = StandardError.new('some error')
- allow(worker)
- .to receive(:find_project)
- .with(project.id)
- .and_return(project)
-
- expect(worker)
- .to receive(:try_import)
- .and_raise(exception)
-
- expect(Gitlab::GithubImport::Logger)
- .to receive(:info)
- .with(
- {
- message: 'starting stage',
- project_id: project.id,
- import_stage: 'DummyStage'
- }
- )
-
- expect(Gitlab::Import::ImportFailureService)
- .to receive(:track)
- .with(
- {
- project_id: project.id,
- exception: exception,
- error_source: 'DummyStage',
- fail_import: false
- }
- ).and_call_original
-
- expect { worker.perform(project.id) }
- .to raise_error(exception)
-
- expect(project.import_state.reload.status).to eq('started')
-
- expect(project.import_failures).not_to be_empty
- expect(project.import_failures.last.exception_class).to eq('StandardError')
- expect(project.import_failures.last.exception_message).to eq('some error')
- end
- end
-
- context 'when abort_on_failure is true' do
- let(:worker) do
- Class.new do
- def self.name
- 'DummyStage'
- end
-
- def abort_on_failure
- true
- end
-
- include(Gitlab::GithubImport::StageMethods)
- end.new
- end
-
- it 'logs, captures and re-raises the exception and also marks the import as failed' do
- exception = StandardError.new('some error')
-
- allow(worker)
- .to receive(:find_project)
- .with(project.id)
- .and_return(project)
+ allow(worker)
+ .to receive(:find_project)
+ .with(project.id)
+ .and_return(project)
- expect(worker)
- .to receive(:try_import)
- .and_raise(exception)
+ expect(worker)
+ .to receive(:try_import)
+ .and_raise(exception)
- expect(Gitlab::GithubImport::Logger)
- .to receive(:info)
- .with(
- {
- message: 'starting stage',
- project_id: project.id,
- import_stage: 'DummyStage'
- }
- )
+ expect(Gitlab::GithubImport::Logger)
+ .to receive(:info)
+ .with(
+ {
+ message: 'starting stage',
+ project_id: project.id,
+ import_stage: 'DummyStage'
+ }
+ )
- expect(Gitlab::Import::ImportFailureService)
- .to receive(:track)
- .with(
+ expect(Gitlab::Import::ImportFailureService)
+ .to receive(:track)
+ .with(
+ {
project_id: project.id,
exception: exception,
error_source: 'DummyStage',
- fail_import: true
- ).and_call_original
+ fail_import: false,
+ metrics: true
+ }
+ ).and_call_original
- expect { worker.perform(project.id) }.to raise_error(exception)
+ expect { worker.perform(project.id) }
+ .to raise_error(exception)
- expect(project.import_state.reload.status).to eq('failed')
- expect(project.import_state.last_error).to eq('some error')
+ expect(project.import_state.reload.status).to eq('started')
- expect(project.import_failures).not_to be_empty
- expect(project.import_failures.last.exception_class).to eq('StandardError')
- expect(project.import_failures.last.exception_message).to eq('some error')
- end
+ expect(project.import_failures).not_to be_empty
+ expect(project.import_failures.last.exception_class).to eq('StandardError')
+ expect(project.import_failures.last.exception_message).to eq('some error')
end
end