diff options
Diffstat (limited to 'spec/workers/gitlab')
3 files changed, 55 insertions, 17 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 8dea24dc74f..132fe1dc618 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 @@ -26,21 +26,18 @@ RSpec.describe Gitlab::GithubImport::Stage::FinishImportWorker do .to receive(:increment) .and_call_original - expect_next_instance_of(Gitlab::Import::Logger) do |logger| - expect(logger) - .to receive(:info) - .with( - message: 'GitHub project import finished', - import_stage: 'Gitlab::GithubImport::Stage::FinishImportWorker', - import_source: :github, - object_counts: { - 'fetched' => {}, - 'imported' => {} - }, - project_id: project.id, - duration_s: a_kind_of(Numeric) - ) - 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) + ) worker.report_import_time(project) 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 bc51a44e057..875fc082975 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 @@ -4,6 +4,7 @@ require 'spec_helper' RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do let(:project) { double(:project, id: 4) } + let(:worker) { described_class.new } describe '#import' do @@ -36,15 +37,19 @@ RSpec.describe Gitlab::GithubImport::Stage::ImportRepositoryWorker do context 'when the import fails' do it 'does not schedule the importing of the base data' do client = double(:client) + exception_class = Gitlab::Git::Repository::NoRepository expect_next_instance_of(Gitlab::GithubImport::Importer::RepositoryImporter) do |instance| - expect(instance).to receive(:execute).and_return(false) + expect(instance).to receive(:execute).and_raise(exception_class) end expect(Gitlab::GithubImport::Stage::ImportBaseDataWorker) .not_to receive(:perform_async) - worker.import(client, project) + expect(worker.abort_on_failure).to eq(true) + + expect { worker.import(client, project) } + .to raise_error(exception_class) end end end diff --git a/spec/workers/gitlab/import/stuck_import_job_spec.rb b/spec/workers/gitlab/import/stuck_import_job_spec.rb new file mode 100644 index 00000000000..3a1463e98a0 --- /dev/null +++ b/spec/workers/gitlab/import/stuck_import_job_spec.rb @@ -0,0 +1,36 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe Gitlab::Import::StuckImportJob do + let_it_be(:project) { create(:project, :import_started, import_source: 'foo/bar') } + + let(:worker) do + Class.new do + def self.name + 'MyStuckProjectImportsWorker' + end + + include(Gitlab::Import::StuckImportJob) + + def track_metrics(...) + nil + end + + def enqueued_import_states + ProjectImportState.with_status([:scheduled, :started]) + end + end.new + end + + it 'marks the stuck import project as failed and track the error on import_failures' do + worker.perform + + expect(project.import_state.reload.status).to eq('failed') + expect(project.import_state.last_error).to eq('Import timed out. Import took longer than 86400 seconds') + + expect(project.import_failures).not_to be_empty + expect(project.import_failures.last.exception_class).to eq('Gitlab::Import::StuckImportJob::StuckImportJobError') + expect(project.import_failures.last.exception_message).to eq('Import timed out. Import took longer than 86400 seconds') + end +end |