diff options
Diffstat (limited to 'spec/workers/concerns/gitlab')
5 files changed, 93 insertions, 39 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 02190201986..18a3e3c2c5b 100644 --- a/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/object_importer_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do +RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures, feature_category: :importers do let(:worker) do Class.new do def self.name @@ -30,7 +30,8 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do let(:github_identifiers) do { some_id: 1, - some_type: '_some_type_' + some_type: '_some_type_', + object_type: 'dummy' } end @@ -52,7 +53,8 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do def github_identifiers { some_id: 1, - some_type: '_some_type_' + some_type: '_some_type_', + object_type: 'dummy' } end end @@ -196,6 +198,19 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do end context 'when the record is invalid' do + let(:exception) { ActiveRecord::RecordInvalid.new } + + before do + expect(importer_class) + .to receive(:new) + .with(instance_of(MockRepresantation), project, client) + .and_return(importer_instance) + + expect(importer_instance) + .to receive(:execute) + .and_raise(exception) + end + it 'logs an error' do expect(Gitlab::GithubImport::Logger) .to receive(:info) @@ -208,16 +223,6 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do } ) - expect(importer_class) - .to receive(:new) - .with(instance_of(MockRepresantation), project, client) - .and_return(importer_instance) - - exception = ActiveRecord::RecordInvalid.new - expect(importer_instance) - .to receive(:execute) - .and_raise(exception) - expect(Gitlab::Import::ImportFailureService) .to receive(:track) .with( @@ -230,6 +235,15 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do worker.import(project, client, { 'number' => 10, 'github_id' => 1 }) end + + it 'updates external_identifiers of the correct failure' do + worker.import(project, client, { 'number' => 10, 'github_id' => 1 }) + + import_failures = project.import_failures + + expect(import_failures.count).to eq(1) + expect(import_failures.first.external_identifiers).to eq(github_identifiers.with_indifferent_access) + end end end @@ -240,4 +254,56 @@ RSpec.describe Gitlab::GithubImport::ObjectImporter, :aggregate_failures do expect(worker).to be_increment_object_counter(issue) end end + + describe '.sidekiq_retries_exhausted' do + let(:correlation_id) { 'abc' } + let(:job) do + { + 'args' => [project.id, { number: 123, state: 'open' }, '123abc'], + 'jid' => '123', + 'correlation_id' => correlation_id + } + end + + subject(:sidekiq_retries_exhausted) { worker.class.sidekiq_retries_exhausted_block.call(job, StandardError.new) } + + context 'when all arguments are given' do + it 'notifies the JobWaiter' do + expect(Gitlab::JobWaiter) + .to receive(:notify) + .with( + job['args'].last, + job['jid'] + ) + + sidekiq_retries_exhausted + end + end + + context 'when not all arguments are given' do + let(:job) do + { + 'args' => [project.id, { number: 123, state: 'open' }], + 'jid' => '123', + 'correlation_id' => correlation_id + } + end + + it 'does not notify the JobWaiter' do + expect(Gitlab::JobWaiter).not_to receive(:notify) + + 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/queue_spec.rb b/spec/workers/concerns/gitlab/github_import/queue_spec.rb deleted file mode 100644 index beca221b593..00000000000 --- a/spec/workers/concerns/gitlab/github_import/queue_spec.rb +++ /dev/null @@ -1,18 +0,0 @@ -# frozen_string_literal: true - -require 'spec_helper' - -RSpec.describe Gitlab::GithubImport::Queue do - it 'sets the Sidekiq options for the worker' do - worker = Class.new do - def self.name - 'DummyWorker' - end - - include ApplicationWorker - include Gitlab::GithubImport::Queue - end - - expect(worker.sidekiq_options['queue']).to eq('github_importer:dummy') - end -end diff --git a/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb index 8727756ce50..cdaff2fc1f4 100644 --- a/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/rescheduling_methods_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::ReschedulingMethods do +RSpec.describe Gitlab::GithubImport::ReschedulingMethods, feature_category: :importers do let(:worker) do Class.new { include(Gitlab::GithubImport::ReschedulingMethods) }.new end @@ -25,9 +25,15 @@ RSpec.describe Gitlab::GithubImport::ReschedulingMethods do end end - context 'with an existing project' do + context 'with an existing project', :clean_gitlab_redis_cache do let(:project) { create(:project, import_url: 'https://t0ken@github.com/repo/repo.git') } + before do + allow_next_instance_of(Gitlab::GithubImport::Client) do |instance| + allow(instance).to receive(:rate_limit_resets_in).and_return(14) + end + end + it 'notifies any waiters upon successfully importing the data' do expect(worker) .to receive(:try_import) @@ -57,13 +63,13 @@ RSpec.describe Gitlab::GithubImport::ReschedulingMethods do expect(worker) .not_to receive(:notify_waiter) - expect_next_instance_of(Gitlab::GithubImport::Client) do |instance| - expect(instance).to receive(:rate_limit_resets_in).and_return(14) - end + expect(worker) + .to receive(:object_type) + .and_return(:pull_request) expect(worker.class) .to receive(:perform_in) - .with(14, project.id, { 'number' => 2 }, '123') + .with(15, project.id, { 'number' => 2 }, '123') worker.perform(project.id, { 'number' => 2 }, '123') 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 0ac1733781a..ce9a9db5dd9 100644 --- a/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb +++ b/spec/workers/concerns/gitlab/github_import/stage_methods_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::GithubImport::StageMethods do +RSpec.describe Gitlab::GithubImport::StageMethods, feature_category: :importers do let_it_be(:project) { create(:project, :import_started, import_url: 'https://t0ken@github.com/repo/repo.git') } let_it_be(:project2) { create(:project, :import_canceled) } diff --git a/spec/workers/concerns/gitlab/notify_upon_death_spec.rb b/spec/workers/concerns/gitlab/notify_upon_death_spec.rb index dd0a1cadc9c..36faf3ee296 100644 --- a/spec/workers/concerns/gitlab/notify_upon_death_spec.rb +++ b/spec/workers/concerns/gitlab/notify_upon_death_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe Gitlab::NotifyUponDeath do +RSpec.describe Gitlab::NotifyUponDeath, feature_category: :shared do let(:worker_class) do Class.new do include Sidekiq::Worker |