Commit 1393e786 authored by Dmitry Gruzd's avatar Dmitry Gruzd

Fix intermitten elastic-related specs failures

parent 61f92c32
......@@ -7,7 +7,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
describe '#save!' do
it 'creates an index if it is not found' do
es_helper.delete_index(index_name: @migrations_index_name)
es_helper.delete_index(index_name: es_helper.migrations_index_name)
expect { record.save!(completed: true) }.to raise_error(/index is not found/)
end
......@@ -55,7 +55,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
completed_versions.each { |migration| migration.save!(completed: true) }
in_progress_migration.save!(completed: false)
es_helper.refresh_index(index_name: @migrations_index_name)
es_helper.refresh_index(index_name: es_helper.migrations_index_name)
end
it 'loads all records' do
......@@ -64,7 +64,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
end
it 'returns empty array if no index present' do
es_helper.delete_index(index_name: @migrations_index_name)
es_helper.delete_index(index_name: es_helper.migrations_index_name)
expect(described_class.persisted_versions(completed: true)).to eq([])
expect(described_class.persisted_versions(completed: false)).to eq([])
......
# frozen_string_literal: true
RSpec.configure do |config|
config.before(:each, :elastic) do
config.around(:each, :elastic) do |example|
helper = Gitlab::Elastic::Helper.default
Elastic::ProcessBookkeepingService.clear_tracking!
Gitlab::Elastic::Helper.default.delete_index
Gitlab::Elastic::Helper.default.create_empty_index(options: { settings: { number_of_replicas: 0 } })
@migrations_index_name = Gitlab::Elastic::Helper.default.create_migrations_index
end
config.after(:each, :elastic) do
Gitlab::Elastic::Helper.default.delete_index
# Delete the migration index and the main ES index
helper.delete_index(index_name: helper.migrations_index_name)
helper.delete_index
helper.create_empty_index(options: { settings: { number_of_replicas: 0 } })
helper.create_migrations_index
example.run
helper.delete_index(index_name: helper.migrations_index_name)
helper.delete_index
Elastic::ProcessBookkeepingService.clear_tracking!
Gitlab::Elastic::Helper.default.delete_index(index_name: @migrations_index_name)
end
config.include ElasticsearchHelpers, :elastic
......
......@@ -36,7 +36,7 @@ module ElasticsearchHelpers
def refresh_index!
es_helper.refresh_index
es_helper.refresh_index(index_name: @migrations_index_name) # rubocop:disable Gitlab/ModuleWithInstanceVariables
es_helper.refresh_index(index_name: es_helper.migrations_index_name)
end
def es_helper
......
......@@ -23,9 +23,9 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
end
it 'creates an index if it does not exist' do
Gitlab::Elastic::Helper.default.delete_index(index_name: @migrations_index_name)
Gitlab::Elastic::Helper.default.delete_index(index_name: es_helper.migrations_index_name)
expect { subject.perform }.to change { Gitlab::Elastic::Helper.default.index_exists?(index_name: @migrations_index_name) }.from(false).to(true)
expect { subject.perform }.to change { Gitlab::Elastic::Helper.default.index_exists?(index_name: es_helper.migrations_index_name) }.from(false).to(true)
end
context 'no unexecuted migrations' do
......
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