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:
authorGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-14 16:40:51 +0300
committerGrzegorz Bizon <grzesiek.bizon@gmail.com>2017-07-14 16:40:51 +0300
commit01c55ffca84aaf2fc957266074ca97183bdaf36a (patch)
tree26e500fce719c2f07aff2f86358b178a0421b94c /spec/lib/gitlab/background_migration_spec.rb
parent39b96f02dca3d6edac40b94bf003e6735c4c2524 (diff)
Catch exceptions when stealing background migrations
Diffstat (limited to 'spec/lib/gitlab/background_migration_spec.rb')
-rw-r--r--spec/lib/gitlab/background_migration_spec.rb61
1 files changed, 43 insertions, 18 deletions
diff --git a/spec/lib/gitlab/background_migration_spec.rb b/spec/lib/gitlab/background_migration_spec.rb
index c12040cba14..b28329792eb 100644
--- a/spec/lib/gitlab/background_migration_spec.rb
+++ b/spec/lib/gitlab/background_migration_spec.rb
@@ -10,40 +10,65 @@ describe Gitlab::BackgroundMigration do
describe '.steal' do
context 'when there are enqueued jobs present' do
- let(:job) { double(:job, args: ['Foo', [10, 20]]) }
- let(:queue) { [job] }
+ let(:queue) do
+ [double(args: ['Foo', [10, 20]], queue: described_class.queue)]
+ end
before do
allow(Sidekiq::Queue).to receive(:new)
.with(described_class.queue)
.and_return(queue)
-
- allow(job).to receive(:queue)
- .and_return(described_class.queue)
end
- it 'steals jobs from a queue' do
- expect(queue[0]).to receive(:delete).and_return(true)
+ context 'when queue contains unprocessed jobs' do
+ it 'steals jobs from a queue' do
+ expect(queue[0]).to receive(:delete).and_return(true)
- expect(described_class).to receive(:perform).with('Foo', [10, 20])
+ expect(described_class).to receive(:perform).with('Foo', [10, 20])
- described_class.steal('Foo')
- end
+ described_class.steal('Foo')
+ end
+
+ it 'does not steal job that has already been taken' do
+ expect(queue[0]).to receive(:delete).and_return(false)
+
+ expect(described_class).not_to receive(:perform).with('Foo', [10, 20])
+
+ described_class.steal('Foo')
+ end
- it 'does not steal job that has already been taken' do
- expect(queue[0]).to receive(:delete).and_return(false)
+ it 'does not steal jobs for a different migration' do
+ expect(described_class).not_to receive(:perform)
- expect(described_class).not_to receive(:perform).with('Foo', [10, 20])
+ expect(queue[0]).not_to receive(:delete)
- described_class.steal('Foo')
+ described_class.steal('Bar')
+ end
end
- it 'does not steal jobs for a different migration' do
- expect(described_class).not_to receive(:perform)
+ context 'when one of the jobs raises an error' do
+ let(:migration) { spy(:migration) }
+
+ let(:queue) do
+ [double(args: ['Foo', [10, 20]], queue: described_class.queue),
+ double(args: ['Foo', [20, 30]], queue: described_class.queue)]
+ end
+
+ before do
+ stub_const("#{described_class}::Foo", migration)
- expect(queue[0]).not_to receive(:delete)
+ allow(migration).to receive(:perform).with(10, 20)
+ .and_raise(StandardError, 'Migration error')
- described_class.steal('Bar')
+ allow(queue[0]).to receive(:delete).and_return(true)
+ allow(queue[1]).to receive(:delete).and_return(true)
+ end
+
+ it 'recovers from an exceptions and continues' do
+ expect(migration).to receive(:perform).twice
+ expect { described_class.steal('Foo') }
+ .to output(/Migration error/).to_stdout
+ end
end
end