Commit e178135d authored by Grzegorz Bizon's avatar Grzegorz Bizon

Add more specs for unique stages index migration

parent 066d4dea
...@@ -11,7 +11,10 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration ...@@ -11,7 +11,10 @@ class RemoveRedundantPipelineStages < ActiveRecord::Migration
add_unique_index! add_unique_index!
rescue ActiveRecord::RecordNotUnique rescue ActiveRecord::RecordNotUnique
retry if (attempts -= 1) > 0 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 end
def down def down
......
...@@ -37,12 +37,23 @@ describe RemoveRedundantPipelineStages, :migration do ...@@ -37,12 +37,23 @@ describe RemoveRedundantPipelineStages, :migration do
expect(builds.all.pluck(:stage_id).compact).to eq [102] expect(builds.all.pluck(:stage_id).compact).to eq [102]
end end
it 'retries when duplicated stages are being created during migration' do it 'retries when incorrectly added index exception is caught' do
allow_any_instance_of(described_class)
.to receive(:remove_redundant_pipeline_stages!)
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!) allow(subject).to receive(:remove_outdated_index!)
expect(subject).to receive(:remove_redundant_pipeline_stages!).exactly(3).times expect(subject).to receive(:remove_redundant_pipeline_stages!).once
allow(subject).to receive(:add_unique_index!) allow(subject).to receive(:add_unique_index!).and_raise(StandardError)
.and_raise(ActiveRecord::RecordNotUnique.new('Duplicated stages present!'))
expect { subject.up(attempts: 3) }.to raise_error ActiveRecord::RecordNotUnique expect { subject.up(attempts: 3) }.to raise_error StandardError
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment