Add more specs for unique stages index migration
This commit is contained in:
parent
066d4deaed
commit
e178135d57
|
@ -11,7 +11,10 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
|
|||
add_unique_index!
|
||||
rescue ActiveRecord::RecordNotUnique
|
||||
retry if (attempts -= 1) > 0
|
||||
raise
|
||||
raise StandardError, <<~EOS
|
||||
Failed to add an unique index to ci_stages, despite retrying the
|
||||
migration 100 times. See gitlab-org/gitlab-ce!16580.
|
||||
EOS
|
||||
end
|
||||
|
||||
def down
|
||||
|
|
|
@ -37,12 +37,23 @@ describe RemoveRedundantPipelineStages, :migration do
|
|||
expect(builds.all.pluck(:stage_id).compact).to eq [102]
|
||||
end
|
||||
|
||||
it 'retries when duplicated stages are being created during migration' do
|
||||
allow(subject).to receive(:remove_outdated_index!)
|
||||
expect(subject).to receive(:remove_redundant_pipeline_stages!).exactly(3).times
|
||||
allow(subject).to receive(:add_unique_index!)
|
||||
.and_raise(ActiveRecord::RecordNotUnique.new('Duplicated stages present!'))
|
||||
it 'retries when incorrectly added index exception is caught' do
|
||||
allow_any_instance_of(described_class)
|
||||
.to receive(:remove_redundant_pipeline_stages!)
|
||||
|
||||
expect { subject.up(attempts: 3) }.to raise_error ActiveRecord::RecordNotUnique
|
||||
expect_any_instance_of(described_class)
|
||||
.to receive(:remove_outdated_index!)
|
||||
.exactly(100).times.and_call_original
|
||||
|
||||
expect { migrate! }
|
||||
.to raise_error StandardError, /Failed to add an unique index/
|
||||
end
|
||||
|
||||
it 'does not retry when unknown exception is being raised' do
|
||||
allow(subject).to receive(:remove_outdated_index!)
|
||||
expect(subject).to receive(:remove_redundant_pipeline_stages!).once
|
||||
allow(subject).to receive(:add_unique_index!).and_raise(StandardError)
|
||||
|
||||
expect { subject.up(attempts: 3) }.to raise_error StandardError
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue