Commit ac97d842 authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '325719-reduce-execution-time-of-search-service-specs-delete-by-query' into 'master'

Elasticsearch Delete by query before examples

See merge request gitlab-org/gitlab!60651
parents 09cffe96 9da2b85e
...@@ -36,7 +36,7 @@ RSpec.describe Search::GlobalService do ...@@ -36,7 +36,7 @@ RSpec.describe Search::GlobalService do
it_behaves_like 'search query applies joins based on migrations shared examples', :add_new_data_to_merge_requests_documents it_behaves_like 'search query applies joins based on migrations shared examples', :add_new_data_to_merge_requests_documents
end end
context 'visibility', :elastic, :sidekiq_inline do context 'visibility', :elastic_delete_by_query, :sidekiq_inline do
include_context 'ProjectPolicyTable context' include_context 'ProjectPolicyTable context'
shared_examples 'search respects visibility' do shared_examples 'search respects visibility' do
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Search::GroupService, :elastic do RSpec.describe Search::GroupService do
include SearchResultHelpers include SearchResultHelpers
include ProjectHelpers include ProjectHelpers
using RSpec::Parameterized::TableSyntax using RSpec::Parameterized::TableSyntax
...@@ -50,7 +50,7 @@ RSpec.describe Search::GroupService, :elastic do ...@@ -50,7 +50,7 @@ RSpec.describe Search::GroupService, :elastic do
ensure_elasticsearch_index! ensure_elasticsearch_index!
end end
context 'finding projects by name', :sidekiq_might_not_need_inline do context 'finding projects by name', :elastic, :sidekiq_might_not_need_inline do
subject { results.objects('projects') } subject { results.objects('projects') }
context 'in parent group' do context 'in parent group' do
...@@ -67,7 +67,7 @@ RSpec.describe Search::GroupService, :elastic do ...@@ -67,7 +67,7 @@ RSpec.describe Search::GroupService, :elastic do
end end
end end
context 'notes search' do context 'notes search', :elastic do
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be(:project) { create(:project, namespace: group) } let_it_be(:project) { create(:project, namespace: group) }
...@@ -76,7 +76,7 @@ RSpec.describe Search::GroupService, :elastic do ...@@ -76,7 +76,7 @@ RSpec.describe Search::GroupService, :elastic do
it_behaves_like 'search query applies joins based on migrations shared examples', :add_permissions_data_to_notes_documents it_behaves_like 'search query applies joins based on migrations shared examples', :add_permissions_data_to_notes_documents
end end
context 'visibility', :sidekiq_inline do context 'visibility', :elastic_delete_by_query, :sidekiq_inline do
include_context 'ProjectPolicyTable context' include_context 'ProjectPolicyTable context'
shared_examples 'search respects visibility' do shared_examples 'search respects visibility' do
...@@ -331,7 +331,7 @@ RSpec.describe Search::GroupService, :elastic do ...@@ -331,7 +331,7 @@ RSpec.describe Search::GroupService, :elastic do
end end
end end
context 'sorting' do context 'sorting', :elastic do
context 'issues' do context 'issues' do
let(:scope) { 'issues' } let(:scope) { 'issues' }
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
......
...@@ -42,7 +42,7 @@ RSpec.describe Search::ProjectService do ...@@ -42,7 +42,7 @@ RSpec.describe Search::ProjectService do
it_behaves_like 'search query applies joins based on migrations shared examples', :add_permissions_data_to_notes_documents it_behaves_like 'search query applies joins based on migrations shared examples', :add_permissions_data_to_notes_documents
end end
context 'visibility', :elastic, :sidekiq_inline do context 'visibility', :elastic_delete_by_query, :sidekiq_inline do
include_context 'ProjectPolicyTable context' include_context 'ProjectPolicyTable context'
shared_examples 'search respects visibility' do shared_examples 'search respects visibility' do
...@@ -51,6 +51,7 @@ RSpec.describe Search::ProjectService do ...@@ -51,6 +51,7 @@ RSpec.describe Search::ProjectService do
projects.each do |project| projects.each do |project|
update_feature_access_level(project, feature_access_level) update_feature_access_level(project, feature_access_level)
end end
ensure_elasticsearch_index! ensure_elasticsearch_index!
expect_search_results(user, scope, expected_count: expected_count) do |user| expect_search_results(user, scope, expected_count: expected_count) do |user|
...@@ -260,6 +261,7 @@ RSpec.describe Search::ProjectService do ...@@ -260,6 +261,7 @@ RSpec.describe Search::ProjectService do
'issues_access_level' => issues_access_level, 'issues_access_level' => issues_access_level,
'merge_requests_access_level' => merge_requests_access_level 'merge_requests_access_level' => merge_requests_access_level
) )
ensure_elasticsearch_index! ensure_elasticsearch_index!
expect_search_results(user, 'milestones', expected_count: expected_count) do |user| expect_search_results(user, 'milestones', expected_count: expected_count) do |user|
......
...@@ -14,14 +14,14 @@ RSpec.describe Search::SnippetService do ...@@ -14,14 +14,14 @@ RSpec.describe Search::SnippetService do
let(:service) { described_class.new(user, params) } let(:service) { described_class.new(user, params) }
end end
describe '#execute', :elastic, :sidekiq_inline do describe '#execute' do
include_context 'ProjectPolicyTable context' include_context 'ProjectPolicyTable context'
before do before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
end end
context 'visibility' do context 'visibility', :elastic_delete_by_query, :sidekiq_inline do
include_context 'ProjectPolicyTable context' include_context 'ProjectPolicyTable context'
include ProjectHelpers include ProjectHelpers
......
# frozen_string_literal: true # frozen_string_literal: true
module Elastic
class TestHelpers
include ElasticsearchHelpers
def helper
@helper ||= Gitlab::Elastic::Helper.default
end
def indices
@indices ||= [helper.target_name, helper.migrations_index_name] + helper.standalone_indices_proxies.map(&:index_name)
end
def setup
clear_tracking!
delete_indices!
helper.create_empty_index(options: { settings: { number_of_replicas: 0 } })
helper.create_migrations_index
::Elastic::DataMigrationService.mark_all_as_completed!
helper.create_standalone_indices
refresh_elasticsearch_index!
end
def teardown
delete_indices!
clear_tracking!
end
def clear_tracking!
Elastic::ProcessInitialBookkeepingService.clear_tracking!
Elastic::ProcessBookkeepingService.clear_tracking!
end
def refresh_elasticsearch_index!
refresh_index!
end
def delete_indices!
indices.each do |index_name|
helper.delete_index(index_name: index_name)
end
end
def delete_all_data_from_index!
helper.client.delete_by_query(
{
index: indices,
body: { query: { match_all: {} } },
slices: 5,
conflicts: 'proceed'
}
)
end
end
end
RSpec.configure do |config| RSpec.configure do |config|
config.around(:each, :elastic) do |example| config.around(:each, :elastic) do |example|
helper = Gitlab::Elastic::Helper.default helper = Elastic::TestHelpers.new
helper.setup
Elastic::ProcessBookkeepingService.clear_tracking! example.run
# Delete all test indices helper.teardown
indices = [helper.target_name, helper.migrations_index_name] + helper.standalone_indices_proxies.map(&:index_name) end
indices.each do |index_name|
helper.delete_index(index_name: index_name) config.before(:context, :elastic_delete_by_query) do
end Elastic::TestHelpers.new.setup
end
helper.create_empty_index(options: { settings: { number_of_replicas: 0 } }) config.after(:context, :elastic_delete_by_query) do
helper.create_migrations_index Elastic::TestHelpers.new.teardown
::Elastic::DataMigrationService.mark_all_as_completed! end
helper.create_standalone_indices
refresh_index! config.around(:each, :elastic_delete_by_query) do |example|
helper = Elastic::TestHelpers.new
helper.refresh_elasticsearch_index!
example.run example.run
indices.each do |index_name| helper.delete_all_data_from_index!
helper.delete_index(index_name: index_name)
end
Elastic::ProcessBookkeepingService.clear_tracking!
end end
config.include ElasticsearchHelpers, :elastic config.include ElasticsearchHelpers, :elastic
config.include ElasticsearchHelpers, :elastic_delete_by_query
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