diff options
Diffstat (limited to 'spec/workers/bulk_imports')
6 files changed, 158 insertions, 19 deletions
diff --git a/spec/workers/bulk_imports/entity_worker_spec.rb b/spec/workers/bulk_imports/entity_worker_spec.rb index 4cd37c93d5f..dada4ef63b3 100644 --- a/spec/workers/bulk_imports/entity_worker_spec.rb +++ b/spec/workers/bulk_imports/entity_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BulkImports::EntityWorker do +RSpec.describe BulkImports::EntityWorker, feature_category: :importers do let_it_be(:entity) { create(:bulk_import_entity) } let_it_be(:pipeline_tracker) do diff --git a/spec/workers/bulk_imports/export_request_worker_spec.rb b/spec/workers/bulk_imports/export_request_worker_spec.rb index 7260e0c0f67..2faa28ba489 100644 --- a/spec/workers/bulk_imports/export_request_worker_spec.rb +++ b/spec/workers/bulk_imports/export_request_worker_spec.rb @@ -80,7 +80,7 @@ RSpec.describe BulkImports::ExportRequestWorker, feature_category: :importers do 'source_full_path' => entity.source_full_path, 'exception.backtrace' => anything, 'exception.class' => 'NoMethodError', - 'exception.message' => "undefined method `model_id' for nil:NilClass", + 'exception.message' => /^undefined method `model_id' for nil:NilClass/, 'message' => 'Failed to fetch source entity id', 'importer' => 'gitlab_migration', 'source_version' => entity.bulk_import.source_version_info.to_s diff --git a/spec/workers/bulk_imports/finish_batched_relation_export_worker_spec.rb b/spec/workers/bulk_imports/finish_batched_relation_export_worker_spec.rb new file mode 100644 index 00000000000..6fbcb267c0a --- /dev/null +++ b/spec/workers/bulk_imports/finish_batched_relation_export_worker_spec.rb @@ -0,0 +1,80 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::FinishBatchedRelationExportWorker, feature_category: :importers do + let(:export) { create(:bulk_import_export, :started) } + let(:batch) { create(:bulk_import_export_batch, :finished, export: export) } + let(:export_id) { export.id } + let(:job_args) { [export_id] } + + describe '#perform' do + it_behaves_like 'an idempotent worker' do + it 'marks export as finished and expires batches cache' do + cache_key = BulkImports::BatchedRelationExportService.cache_key(export.id, batch.id) + + expect(Gitlab::Cache::Import::Caching).to receive(:expire).with(cache_key, 0) + + perform_multiple(job_args) + + expect(export.reload.finished?).to eq(true) + end + + context 'when export is finished' do + let(:export) { create(:bulk_import_export, :finished) } + + it 'returns without updating export' do + perform_multiple(job_args) + + expect(export.reload.finished?).to eq(true) + end + end + + context 'when export is failed' do + let(:export) { create(:bulk_import_export, :failed) } + + it 'returns without updating export' do + perform_multiple(job_args) + + expect(export.reload.failed?).to eq(true) + end + end + + context 'when export is in progress' do + it 'reenqueues itself' do + create(:bulk_import_export_batch, :started, export: export) + + expect(described_class).to receive(:perform_in).twice + + perform_multiple(job_args) + + expect(export.reload.started?).to eq(true) + end + end + + context 'when export timed out' do + it 'marks export as failed' do + expect(export.reload.failed?).to eq(false) + expect(batch.reload.failed?).to eq(false) + + export.update!(updated_at: 1.day.ago) + + perform_multiple(job_args) + + expect(export.reload.failed?).to eq(true) + expect(batch.reload.failed?).to eq(true) + end + end + + context 'when export is missing' do + let(:export_id) { nil } + + it 'returns' do + expect(described_class).not_to receive(:perform_in) + + perform_multiple(job_args) + end + end + end + end +end diff --git a/spec/workers/bulk_imports/relation_batch_export_worker_spec.rb b/spec/workers/bulk_imports/relation_batch_export_worker_spec.rb new file mode 100644 index 00000000000..4a2c8d48742 --- /dev/null +++ b/spec/workers/bulk_imports/relation_batch_export_worker_spec.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +require 'spec_helper' + +RSpec.describe BulkImports::RelationBatchExportWorker, feature_category: :importers do + let_it_be(:user) { create(:user) } + let_it_be(:batch) { create(:bulk_import_export_batch) } + + let(:job_args) { [user.id, batch.id] } + + describe '#perform' do + include_examples 'an idempotent worker' do + it 'executes RelationBatchExportService' do + service = instance_double(BulkImports::RelationBatchExportService) + + expect(BulkImports::RelationBatchExportService) + .to receive(:new) + .with(user.id, batch.id) + .twice.and_return(service) + expect(service).to receive(:execute).twice + + perform_multiple(job_args) + end + end + end +end diff --git a/spec/workers/bulk_imports/relation_export_worker_spec.rb b/spec/workers/bulk_imports/relation_export_worker_spec.rb index 63f1992d186..f91db0388a4 100644 --- a/spec/workers/bulk_imports/relation_export_worker_spec.rb +++ b/spec/workers/bulk_imports/relation_export_worker_spec.rb @@ -2,19 +2,20 @@ require 'spec_helper' -RSpec.describe BulkImports::RelationExportWorker do +RSpec.describe BulkImports::RelationExportWorker, feature_category: :importers do let_it_be(:jid) { 'jid' } - let_it_be(:relation) { 'labels' } let_it_be(:user) { create(:user) } let_it_be(:group) { create(:group) } - let(:job_args) { [user.id, group.id, group.class.name, relation] } + let(:batched) { false } + let(:relation) { 'labels' } + let(:job_args) { [user.id, group.id, group.class.name, relation, batched] } describe '#perform' do include_examples 'an idempotent worker' do context 'when export record does not exist' do let(:another_group) { create(:group) } - let(:job_args) { [user.id, another_group.id, another_group.class.name, relation] } + let(:job_args) { [user.id, another_group.id, another_group.class.name, relation, batched] } it 'creates export record' do another_group.add_owner(user) @@ -26,21 +27,53 @@ RSpec.describe BulkImports::RelationExportWorker do end end - it 'executes RelationExportService' do - group.add_owner(user) + shared_examples 'export service' do |export_service| + it 'executes export service' do + group.add_owner(user) - service = instance_double(BulkImports::RelationExportService) + service = instance_double(export_service) - expect(BulkImports::RelationExportService) - .to receive(:new) - .with(user, group, relation, anything) - .twice - .and_return(service) - expect(service) - .to receive(:execute) - .twice + expect(export_service) + .to receive(:new) + .with(user, group, relation, anything) + .twice + .and_return(service) + expect(service).to receive(:execute).twice - perform_multiple(job_args) + perform_multiple(job_args) + end + end + + context 'when export is batched' do + let(:batched) { true } + + context 'when bulk_imports_batched_import_export feature flag is disabled' do + before do + stub_feature_flags(bulk_imports_batched_import_export: false) + end + + include_examples 'export service', BulkImports::RelationExportService + end + + context 'when bulk_imports_batched_import_export feature flag is enabled' do + before do + stub_feature_flags(bulk_imports_batched_import_export: true) + end + + context 'when relation is batchable' do + include_examples 'export service', BulkImports::BatchedRelationExportService + end + + context 'when relation is not batchable' do + let(:relation) { 'namespace_settings' } + + include_examples 'export service', BulkImports::RelationExportService + end + end + end + + context 'when export is not batched' do + include_examples 'export service', BulkImports::RelationExportService end end end diff --git a/spec/workers/bulk_imports/stuck_import_worker_spec.rb b/spec/workers/bulk_imports/stuck_import_worker_spec.rb index 7dfb6532c07..ba1b1b66b00 100644 --- a/spec/workers/bulk_imports/stuck_import_worker_spec.rb +++ b/spec/workers/bulk_imports/stuck_import_worker_spec.rb @@ -2,7 +2,7 @@ require 'spec_helper' -RSpec.describe BulkImports::StuckImportWorker do +RSpec.describe BulkImports::StuckImportWorker, feature_category: :importers do let_it_be(:created_bulk_import) { create(:bulk_import, :created) } let_it_be(:started_bulk_import) { create(:bulk_import, :started) } let_it_be(:stale_created_bulk_import) { create(:bulk_import, :created, created_at: 3.days.ago) } |