diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-08-19 12:08:42 +0300 |
commit | b76ae638462ab0f673e5915986070518dd3f9ad3 (patch) | |
tree | bdab0533383b52873be0ec0eb4d3c66598ff8b91 /spec/lib/gitlab/background_migration_spec.rb | |
parent | 434373eabe7b4be9593d18a585fb763f1e5f1a6f (diff) |
Add latest changes from gitlab-org/gitlab@14-2-stable-eev14.2.0-rc42
Diffstat (limited to 'spec/lib/gitlab/background_migration_spec.rb')
-rw-r--r-- | spec/lib/gitlab/background_migration_spec.rb | 66 |
1 files changed, 35 insertions, 31 deletions
diff --git a/spec/lib/gitlab/background_migration_spec.rb b/spec/lib/gitlab/background_migration_spec.rb index 5b20572578c..f32e6891716 100644 --- a/spec/lib/gitlab/background_migration_spec.rb +++ b/spec/lib/gitlab/background_migration_spec.rb @@ -13,7 +13,11 @@ RSpec.describe Gitlab::BackgroundMigration do describe '.steal' do context 'when there are enqueued jobs present' do let(:queue) do - [double(args: ['Foo', [10, 20]], queue: described_class.queue)] + [ + double(args: ['Foo', [10, 20]], klass: 'BackgroundMigrationWorker'), + double(args: ['Bar', [20, 30]], klass: 'BackgroundMigrationWorker'), + double(args: ['Foo', [20, 30]], klass: 'MergeWorker') + ] end before do @@ -45,7 +49,7 @@ RSpec.describe Gitlab::BackgroundMigration do expect(queue[0]).not_to receive(:delete) - described_class.steal('Bar') + described_class.steal('Baz') end context 'when a custom predicate is given' do @@ -72,8 +76,8 @@ RSpec.describe Gitlab::BackgroundMigration 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)] + [double(args: ['Foo', [10, 20]], klass: 'BackgroundMigrationWorker'), + double(args: ['Foo', [20, 30]], klass: 'BackgroundMigrationWorker')] end before do @@ -128,11 +132,11 @@ RSpec.describe Gitlab::BackgroundMigration do context 'when retry_dead_jobs is true', :redis do let(:retry_queue) do - [double(args: ['Object', [3]], queue: described_class.queue, delete: true)] + [double(args: ['Object', [3]], klass: 'BackgroundMigrationWorker', delete: true)] end let(:dead_queue) do - [double(args: ['Object', [4]], queue: described_class.queue, delete: true)] + [double(args: ['Object', [4]], klass: 'BackgroundMigrationWorker', delete: true)] end before do @@ -187,20 +191,22 @@ RSpec.describe Gitlab::BackgroundMigration do describe '.remaining', :redis do context 'when there are jobs remaining' do - let(:queue) { Array.new(12) } - before do - allow(Sidekiq::Queue).to receive(:new) - .with(described_class.queue) - .and_return(Array.new(12)) - Sidekiq::Testing.disable! do - BackgroundMigrationWorker.perform_in(10.minutes, 'Foo') + MergeWorker.perform_async('Foo') + MergeWorker.perform_in(10.minutes, 'Foo') + + 5.times do + BackgroundMigrationWorker.perform_async('Foo') + end + 3.times do + BackgroundMigrationWorker.perform_in(10.minutes, 'Foo') + end end end it 'returns the enqueued jobs plus the scheduled jobs' do - expect(described_class.remaining).to eq(13) + expect(described_class.remaining).to eq(8) end end @@ -211,16 +217,13 @@ RSpec.describe Gitlab::BackgroundMigration do end end - describe '.exists?' do + describe '.exists?', :redis do context 'when there are enqueued jobs present' do - 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) + Sidekiq::Testing.disable! do + MergeWorker.perform_async('Bar') + BackgroundMigrationWorker.perform_async('Foo') + end end it 'returns true if specific job exists' do @@ -232,19 +235,14 @@ RSpec.describe Gitlab::BackgroundMigration do end end - context 'when there are scheduled jobs present', :redis do + context 'when there are scheduled jobs present' do before do Sidekiq::Testing.disable! do + MergeWorker.perform_in(10.minutes, 'Bar') BackgroundMigrationWorker.perform_in(10.minutes, 'Foo') - - expect(Sidekiq::ScheduledSet.new).to be_one end end - after do - Sidekiq::ScheduledSet.new.clear - end - it 'returns true if specific job exists' do expect(described_class.exists?('Foo')).to eq(true) end @@ -257,7 +255,10 @@ RSpec.describe Gitlab::BackgroundMigration do describe '.dead_jobs?' do let(:queue) do - [double(args: ['Foo', [10, 20]], queue: described_class.queue)] + [ + double(args: ['Foo', [10, 20]], klass: 'BackgroundMigrationWorker'), + double(args: ['Bar'], klass: 'MergeWorker') + ] end context 'when there are dead jobs present' do @@ -277,7 +278,10 @@ RSpec.describe Gitlab::BackgroundMigration do describe '.retrying_jobs?' do let(:queue) do - [double(args: ['Foo', [10, 20]], queue: described_class.queue)] + [ + double(args: ['Foo', [10, 20]], klass: 'BackgroundMigrationWorker'), + double(args: ['Bar'], klass: 'MergeWorker') + ] end context 'when there are dead jobs present' do |