Welcome to mirror list, hosted at ThFree Co, Russian Federation.

gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb5
-rw-r--r--spec/migrations/remove_redundant_pipeline_stages_spec.rb21
2 files changed, 20 insertions, 6 deletions
diff --git a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
index 9644cfabb60..6783b717543 100644
--- a/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
+++ b/db/post_migrate/20180119121225_remove_redundant_pipeline_stages.rb
@@ -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
diff --git a/spec/migrations/remove_redundant_pipeline_stages_spec.rb b/spec/migrations/remove_redundant_pipeline_stages_spec.rb
index b2b6446f2c8..8325f986594 100644
--- a/spec/migrations/remove_redundant_pipeline_stages_spec.rb
+++ b/spec/migrations/remove_redundant_pipeline_stages_spec.rb
@@ -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
+ 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!)
- 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!'))
+ 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 ActiveRecord::RecordNotUnique
+ expect { subject.up(attempts: 3) }.to raise_error StandardError
end
end