diff options
author | Rémy Coutable <remy@rymai.me> | 2017-06-12 19:51:54 +0300 |
---|---|---|
committer | Rémy Coutable <remy@rymai.me> | 2017-06-12 19:51:54 +0300 |
commit | e889b4e8c2f9e31ceac6e456793de357d96067f7 (patch) | |
tree | 59fc24f1980f53dcf6f223b6dc6e12108fa9d1a2 /spec/lib | |
parent | de23d651e0a6b31b21c416c073ddf9e8ff97ade5 (diff) | |
parent | d83ee2bbd10d8fe2f2e9521bb3c266cf696aa98c (diff) |
Merge branch 'background-migrations' into 'master'
Add the ability to perform background migrations
See merge request !11854
Diffstat (limited to 'spec/lib')
-rw-r--r-- | spec/lib/gitlab/background_migration_spec.rb | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/spec/lib/gitlab/background_migration_spec.rb b/spec/lib/gitlab/background_migration_spec.rb new file mode 100644 index 00000000000..f2073b9bcb3 --- /dev/null +++ b/spec/lib/gitlab/background_migration_spec.rb @@ -0,0 +1,48 @@ +require 'spec_helper' + +describe Gitlab::BackgroundMigration do + describe '.steal' do + it 'steals jobs from a queue' do + queue = [double(:job, args: ['Foo', [10, 20]])] + + allow(Sidekiq::Queue).to receive(:new). + with(BackgroundMigrationWorker.sidekiq_options['queue']). + and_return(queue) + + expect(queue[0]).to receive(:delete) + + expect(described_class).to receive(:perform).with('Foo', [10, 20]) + + described_class.steal('Foo') + end + + it 'does not steal jobs for a different migration' do + queue = [double(:job, args: ['Foo', [10, 20]])] + + allow(Sidekiq::Queue).to receive(:new). + with(BackgroundMigrationWorker.sidekiq_options['queue']). + and_return(queue) + + expect(described_class).not_to receive(:perform) + + expect(queue[0]).not_to receive(:delete) + + described_class.steal('Bar') + end + end + + describe '.perform' do + it 'performs a background migration' do + instance = double(:instance) + klass = double(:klass, new: instance) + + expect(described_class).to receive(:const_get). + with('Foo'). + and_return(klass) + + expect(instance).to receive(:perform).with(10, 20) + + described_class.perform('Foo', [10, 20]) + end + end +end |