summaryrefslogtreecommitdiff
path: root/spec/migrations/finalize_project_namespaces_backfill_spec.rb
diff options
context:
space:
mode:
Diffstat (limited to 'spec/migrations/finalize_project_namespaces_backfill_spec.rb')
-rw-r--r--spec/migrations/finalize_project_namespaces_backfill_spec.rb69
1 files changed, 69 insertions, 0 deletions
diff --git a/spec/migrations/finalize_project_namespaces_backfill_spec.rb b/spec/migrations/finalize_project_namespaces_backfill_spec.rb
new file mode 100644
index 00000000000..3d0b0ec13fe
--- /dev/null
+++ b/spec/migrations/finalize_project_namespaces_backfill_spec.rb
@@ -0,0 +1,69 @@
+# frozen_string_literal: true
+
+require 'spec_helper'
+require_migration!
+
+RSpec.describe FinalizeProjectNamespacesBackfill, :migration do
+ let(:batched_migrations) { table(:batched_background_migrations) }
+
+ let_it_be(:migration) { described_class::MIGRATION }
+
+ describe '#up' do
+ shared_examples 'raises migration not finished exception' do
+ it 'raises exception' do
+ expect { migrate! }.to raise_error(/Expected batched background migration for the given configuration to be marked as 'finished'/)
+ end
+ end
+
+ context 'when project namespace backfilling migration is missing' do
+ it 'warns migration not found' do
+ expect(Gitlab::AppLogger)
+ .to receive(:warn).with(/Could not find batched background migration for the given configuration:/)
+
+ migrate!
+ end
+ end
+
+ context 'with backfilling migration present' do
+ let!(:project_namespace_backfill) do
+ batched_migrations.create!(
+ job_class_name: 'ProjectNamespaces::BackfillProjectNamespaces',
+ table_name: :projects,
+ column_name: :id,
+ job_arguments: [nil, 'up'],
+ interval: 2.minutes,
+ min_value: 1,
+ max_value: 2,
+ batch_size: 1000,
+ sub_batch_size: 200,
+ status: 3 # finished
+ )
+ end
+
+ context 'when project namespace backfilling migration finished successfully' do
+ it 'does not raise exception' do
+ expect { migrate! }.not_to raise_error(/Expected batched background migration for the given configuration to be marked as 'finished'/)
+ end
+ end
+
+ context 'when project namespace backfilling migration is paused' do
+ using RSpec::Parameterized::TableSyntax
+
+ where(:status, :description) do
+ 0 | 'paused'
+ 1 | 'active'
+ 4 | 'failed'
+ 5 | 'finalizing'
+ end
+
+ with_them do
+ before do
+ project_namespace_backfill.update!(status: status)
+ end
+
+ it_behaves_like 'raises migration not finished exception'
+ end
+ end
+ end
+ end
+end