Commit afd257ba authored by Krasimir Angelov's avatar Krasimir Angelov

Merge branch '343047-restore-background-migration-remaining' into 'master'

Restore the BackgroundMigration.remaining method

See merge request gitlab-org/gitlab!74015
parents 0000d668 7c08a8fa
...@@ -42,5 +42,9 @@ module Gitlab ...@@ -42,5 +42,9 @@ module Gitlab
def self.exists?(migration_class, additional_queues = [], database: :main) def self.exists?(migration_class, additional_queues = [], database: :main)
coordinator_for_database(database).exists?(migration_class, additional_queues) # rubocop:disable CodeReuse/ActiveRecord coordinator_for_database(database).exists?(migration_class, additional_queues) # rubocop:disable CodeReuse/ActiveRecord
end end
def self.remaining(database: :main)
coordinator_for_database(database).remaining
end
end end
end end
...@@ -34,7 +34,7 @@ RSpec.describe Gitlab::BackgroundMigration do ...@@ -34,7 +34,7 @@ RSpec.describe Gitlab::BackgroundMigration do
.and_return(queue) .and_return(queue)
end end
it 'uses the job executor to steal jobs' do it 'uses the coordinator to steal jobs' do
expect(queue[0]).to receive(:delete).and_return(true) expect(queue[0]).to receive(:delete).and_return(true)
expect(coordinator).to receive(:steal).with('Foo', retry_dead_jobs: false).and_call_original expect(coordinator).to receive(:steal).with('Foo', retry_dead_jobs: false).and_call_original
...@@ -99,7 +99,7 @@ RSpec.describe Gitlab::BackgroundMigration do ...@@ -99,7 +99,7 @@ RSpec.describe Gitlab::BackgroundMigration do
stub_const("#{described_class.name}::Foo", migration) stub_const("#{described_class.name}::Foo", migration)
end end
it 'uses the job executor to perform a background migration' do it 'uses the coordinator to perform a background migration' do
expect(coordinator).to receive(:perform).with('Foo', [10, 20]).and_call_original expect(coordinator).to receive(:perform).with('Foo', [10, 20]).and_call_original
expect(migration).to receive(:perform).with(10, 20).once expect(migration).to receive(:perform).with(10, 20).once
...@@ -108,25 +108,45 @@ RSpec.describe Gitlab::BackgroundMigration do ...@@ -108,25 +108,45 @@ RSpec.describe Gitlab::BackgroundMigration do
end end
describe '.exists?', :redis do describe '.exists?', :redis do
context 'when there are enqueued jobs present' do before do
before do Sidekiq::Testing.disable! do
Sidekiq::Testing.disable! do MergeWorker.perform_async('Bar')
MergeWorker.perform_async('Bar') BackgroundMigrationWorker.perform_async('Foo')
BackgroundMigrationWorker.perform_async('Foo')
end
end end
end
it 'uses the job executor to find if a job exists' do it 'uses the coordinator to find if a job exists' do
expect(coordinator).to receive(:exists?).with('Foo', []).and_call_original expect(coordinator).to receive(:exists?).with('Foo', []).and_call_original
expect(described_class.exists?('Foo')).to eq(true) expect(described_class.exists?('Foo')).to eq(true)
end end
it 'uses the job executor to find a job does not exist' do it 'uses the coordinator to find a job does not exist' do
expect(coordinator).to receive(:exists?).with('Bar', []).and_call_original expect(coordinator).to receive(:exists?).with('Bar', []).and_call_original
expect(described_class.exists?('Bar')).to eq(false) expect(described_class.exists?('Bar')).to eq(false)
end
end
describe '.remaining', :redis do
before do
Sidekiq::Testing.disable! do
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
end end
it 'uses the coordinator to find the number of remaining jobs' do
expect(coordinator).to receive(:remaining).and_call_original
expect(described_class.remaining).to eq(8)
end
end end
end end
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment