Commit f682052a authored by Dmitry Gruzd's avatar Dmitry Gruzd

Fix Elastic::MigrationWorker current_migration

Changelog: fixed
EE: true
parent 2c1838e7
...@@ -87,9 +87,9 @@ module Elastic ...@@ -87,9 +87,9 @@ module Elastic
end end
def current_migration def current_migration
completed_migrations = Elastic::MigrationRecord.load_versions(completed: true) uncompleted_migrations = Elastic::MigrationRecord.load_versions(completed: false)
Elastic::DataMigrationService.migrations.find { |migration| !completed_migrations.include?(migration.version) } Elastic::DataMigrationService.migrations.find { |migration| uncompleted_migrations.include?(migration.version) }
end end
def pause_indexing!(migration) def pause_indexing!(migration)
......
...@@ -22,7 +22,10 @@ RSpec.describe Elastic::MigrationWorker, :elastic do ...@@ -22,7 +22,10 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
before do before do
stub_ee_application_setting(elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_indexing: true)
end
context 'an unexecuted migration present' do
before do
allow(subject).to receive(:current_migration).and_return(migration) allow(subject).to receive(:current_migration).and_return(migration)
end end
...@@ -32,18 +35,6 @@ RSpec.describe Elastic::MigrationWorker, :elastic do ...@@ -32,18 +35,6 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
expect { subject.perform }.to change { Gitlab::Elastic::Helper.default.migrations_index_exists? }.from(false).to(true) expect { subject.perform }.to change { Gitlab::Elastic::Helper.default.migrations_index_exists? }.from(false).to(true)
end end
context 'no unexecuted migrations' do
before do
allow(subject).to receive(:current_migration).and_return(nil)
end
it 'skips execution' do
expect(subject).not_to receive(:execute_migration)
expect(subject.perform).to be_falsey
end
end
context 'migration is halted' do context 'migration is halted' do
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
...@@ -187,5 +178,30 @@ RSpec.describe Elastic::MigrationWorker, :elastic do ...@@ -187,5 +178,30 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
end end
end end
end end
context 'no unexecuted migrations' do
before do
allow(subject).to receive(:current_migration).and_return(nil)
end
it 'skips execution' do
expect(subject).not_to receive(:execute_migration)
expect(subject.perform).to be_falsey
end
end
context 'load_versions returns empty array' do
before do
allow(Elastic::MigrationRecord).to receive(:load_versions).and_return([])
end
it 'skips execution' do
expect(subject).not_to receive(:execute_migration)
expect(subject.perform).to be_falsey
end
end
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