Commit 20ee0b94 authored by Dylan Griffith's avatar Dylan Griffith

Merge branch 'fix-intermittent-specs-failures' into 'master'

Fix intermittent elastic-related specs failures

See merge request gitlab-org/gitlab!48112
parents d6284876 1393e786
...@@ -7,7 +7,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do ...@@ -7,7 +7,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
describe '#save!' do describe '#save!' do
it 'creates an index if it is not found' 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/) expect { record.save!(completed: true) }.to raise_error(/index is not found/)
end end
...@@ -55,7 +55,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do ...@@ -55,7 +55,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
completed_versions.each { |migration| migration.save!(completed: true) } completed_versions.each { |migration| migration.save!(completed: true) }
in_progress_migration.save!(completed: false) 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 end
it 'loads all records' do it 'loads all records' do
...@@ -64,7 +64,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do ...@@ -64,7 +64,7 @@ RSpec.describe Elastic::MigrationRecord, :elastic do
end end
it 'returns empty array if no index present' do 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: true)).to eq([])
expect(described_class.persisted_versions(completed: false)).to eq([]) expect(described_class.persisted_versions(completed: false)).to eq([])
......
# frozen_string_literal: true # frozen_string_literal: true
RSpec.configure do |config| RSpec.configure do |config|
config.before(:each, :elastic) do config.around(:each, :elastic) do |example|
helper = Gitlab::Elastic::Helper.default
Elastic::ProcessBookkeepingService.clear_tracking! 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 # Delete the migration index and the main ES index
Gitlab::Elastic::Helper.default.delete_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! Elastic::ProcessBookkeepingService.clear_tracking!
Gitlab::Elastic::Helper.default.delete_index(index_name: @migrations_index_name)
end end
config.include ElasticsearchHelpers, :elastic config.include ElasticsearchHelpers, :elastic
......
...@@ -36,7 +36,7 @@ module ElasticsearchHelpers ...@@ -36,7 +36,7 @@ module ElasticsearchHelpers
def refresh_index! def refresh_index!
es_helper.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 end
def es_helper def es_helper
......
...@@ -23,9 +23,9 @@ RSpec.describe Elastic::MigrationWorker, :elastic do ...@@ -23,9 +23,9 @@ RSpec.describe Elastic::MigrationWorker, :elastic do
end end
it 'creates an index if it does not exist' do 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 end
context 'no unexecuted migrations' do 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