summaryrefslogtreecommitdiff
path: root/spec/lib/gitlab/background_migration_spec.rb
diff options
context:
space:
mode:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-17 14:02:12 +0200
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-17 14:02:12 +0200
commite41d42d6a2f5775b8f165cb00617dc956d3ca097 (patch)
treec4d988640e90bdfde79bb8349723236cce1f902d /spec/lib/gitlab/background_migration_spec.rb
parentaf41bd41e9c018eaac4ba9f1e6165aeea894f824 (diff)
downloadgitlab-ce-e41d42d6a2f5775b8f165cb00617dc956d3ca097.tar.gz
Simplify background migrations stealing code
Simply re-raise an exception when it occurs, but guarantee that no background migration is lost in the process.
Diffstat (limited to 'spec/lib/gitlab/background_migration_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration_spec.rb68
1 files changed, 9 insertions, 59 deletions
diff --git a/spec/lib/gitlab/background_migration_spec.rb b/spec/lib/gitlab/background_migration_spec.rb
index 64f59c72cec..cfa59280139 100644
--- a/spec/lib/gitlab/background_migration_spec.rb
+++ b/spec/lib/gitlab/background_migration_spec.rb
@@ -62,32 +62,14 @@ describe Gitlab::BackgroundMigration do
allow(queue[1]).to receive(:delete).and_return(true)
end
- context 'when standard error is being raised' do
- it 'recovers from an exception and retries the migration' do
- expect(migration).to receive(:perform).with(10, 20)
- .and_raise(StandardError, 'Migration error')
- .exactly(4).times.ordered
- expect(migration).to receive(:perform).with(20, 30)
- .once.ordered
- expect(Rails.logger).to receive(:warn)
- .with(/Retrying background migration/).exactly(3).times
-
- described_class.steal('Foo')
- end
- end
-
- context 'when top level exception is being raised' do
- it 'enqueues the migration again and reraises the error' do
- allow(migration).to receive(:perform).with(10, 20)
- .and_raise(Exception, 'Migration error').once
+ it 'enqueues the migration again and re-raises the error' do
+ allow(migration).to receive(:perform).with(10, 20)
+ .and_raise(Exception, 'Migration error').once
- expect(BackgroundMigrationWorker).to receive(:perform_async)
- .with('Foo', [10, 20]).once
+ expect(BackgroundMigrationWorker).to receive(:perform_async)
+ .with('Foo', [10, 20]).once
- expect(Rails.logger).not_to receive(:warn)
- expect { described_class.steal('Foo') }
- .to raise_error(Exception)
- end
+ expect { described_class.steal('Foo') }.to raise_error(Exception)
end
end
end
@@ -131,42 +113,10 @@ describe Gitlab::BackgroundMigration do
stub_const("#{described_class.name}::Foo", migration)
end
- context 'when retries count is not specified' do
- it 'performs a background migration' do
- expect(migration).to receive(:perform).with(10, 20).once
-
- described_class.perform('Foo', [10, 20])
- end
- end
-
- context 'when retries count is zero' do
- it 'perform a background migration only once' do
- expect(migration).to receive(:perform).with(10, 20)
- .and_raise(StandardError).once
+ it 'performs a background migration' do
+ expect(migration).to receive(:perform).with(10, 20).once
- expect { described_class.perform('Foo', [10, 20], retries: 0) }
- .to raise_error(StandardError)
- end
- end
-
- context 'when retries count is one' do
- it 'retries a background migration when needed' do
- expect(migration).to receive(:perform).with(10, 20)
- .and_raise(StandardError).twice
-
- expect { described_class.perform('Foo', [10, 20], retries: 1) }
- .to raise_error(StandardError)
- end
- end
-
- context 'when retries count is larger than zero' do
- it 'retries a background migration when needed' do
- expect(migration).to receive(:perform).with(10, 20)
- .and_raise(StandardError).exactly(4).times
-
- expect { described_class.perform('Foo', [10, 20], retries: 3) }
- .to raise_error(StandardError)
- end
+ described_class.perform('Foo', [10, 20])
end
end
end