Commit e1464d93 authored by Robert May's avatar Robert May

Merge branch 'pl-spec-search-global-service-perf' into 'master'

Improve performance of search global service spec

See merge request gitlab-org/gitlab!78377
parents 40ee5e24 0a0dc272
...@@ -5,9 +5,8 @@ require 'spec_helper' ...@@ -5,9 +5,8 @@ require 'spec_helper'
RSpec.describe Search::GlobalService do RSpec.describe Search::GlobalService do
include SearchResultHelpers include SearchResultHelpers
include ProjectHelpers include ProjectHelpers
using RSpec::Parameterized::TableSyntax
let(:user) { create(:user) } let_it_be(:user) { create(:user) }
before do before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true) stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
...@@ -40,6 +39,7 @@ RSpec.describe Search::GlobalService do ...@@ -40,6 +39,7 @@ RSpec.describe Search::GlobalService do
shared_examples 'search respects visibility' do shared_examples 'search respects visibility' do
it 'respects visibility' do it 'respects visibility' do
enable_admin_mode!(user) if admin_mode enable_admin_mode!(user) if admin_mode
project.update!(visibility_level: Gitlab::VisibilityLevel.level_value(project_level.to_s))
update_feature_access_level(project, feature_access_level) update_feature_access_level(project, feature_access_level)
ensure_elasticsearch_index! ensure_elasticsearch_index!
...@@ -50,8 +50,8 @@ RSpec.describe Search::GlobalService do ...@@ -50,8 +50,8 @@ RSpec.describe Search::GlobalService do
end end
let_it_be(:group) { create(:group) } let_it_be(:group) { create(:group) }
let_it_be_with_reload(:project) { create(:project, namespace: group) }
let(:project) { create(:project, project_level, namespace: group) }
let(:user) { create_user_from_membership(project, membership) } let(:user) { create_user_from_membership(project, membership) }
context 'merge request' do context 'merge request' do
...@@ -91,7 +91,7 @@ RSpec.describe Search::GlobalService do ...@@ -91,7 +91,7 @@ RSpec.describe Search::GlobalService do
end end
context 'blob and commit' do context 'blob and commit' do
let!(:project) { create(:project, project_level, :repository, namespace: group ) } let_it_be_with_reload(:project) { create(:project, :repository, namespace: group) }
where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do
permission_table_for_guest_feature_access_and_non_private_project_only permission_table_for_guest_feature_access_and_non_private_project_only
...@@ -143,7 +143,8 @@ RSpec.describe Search::GlobalService do ...@@ -143,7 +143,8 @@ RSpec.describe Search::GlobalService do
end end
context 'on commits' do context 'on commits' do
let!(:project) { create(:project, project_level, :repository, namespace: group ) } let_it_be_with_reload(:project) { create(:project, :repository, namespace: group) }
let!(:note) { create :note_on_commit, project: project } let!(:note) { create :note_on_commit, project: project }
where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do where(:project_level, :feature_access_level, :membership, :admin_mode, :expected_count) do
...@@ -188,7 +189,8 @@ RSpec.describe Search::GlobalService do ...@@ -188,7 +189,8 @@ RSpec.describe Search::GlobalService do
end end
context 'wiki' do context 'wiki' do
let!(:project) { create(:project, project_level, :wiki_repo) } let_it_be_with_reload(:project) { create(:project, :wiki_repo) }
let(:scope) { 'wiki_blobs' } let(:scope) { 'wiki_blobs' }
let(:search) { 'term' } let(:search) { 'term' }
...@@ -219,8 +221,9 @@ RSpec.describe Search::GlobalService do ...@@ -219,8 +221,9 @@ RSpec.describe Search::GlobalService do
it "respects visibility" do it "respects visibility" do
enable_admin_mode!(user) if admin_mode enable_admin_mode!(user) if admin_mode
project.update!( project.update!(
'issues_access_level' => issues_access_level, visibility_level: Gitlab::VisibilityLevel.level_value(project_level.to_s),
'merge_requests_access_level' => merge_requests_access_level issues_access_level: issues_access_level,
merge_requests_access_level: merge_requests_access_level
) )
ensure_elasticsearch_index! ensure_elasticsearch_index!
...@@ -238,6 +241,8 @@ RSpec.describe Search::GlobalService do ...@@ -238,6 +241,8 @@ RSpec.describe Search::GlobalService do
with_them do with_them do
it "respects visibility" do it "respects visibility" do
project.update!(visibility_level: Gitlab::VisibilityLevel.level_value(project_level.to_s))
ElasticCommitIndexerWorker.new.perform(project.id) ElasticCommitIndexerWorker.new.perform(project.id)
ensure_elasticsearch_index! ensure_elasticsearch_index!
...@@ -258,8 +263,9 @@ RSpec.describe Search::GlobalService do ...@@ -258,8 +263,9 @@ RSpec.describe Search::GlobalService do
context 'sorting', :elastic, :clean_gitlab_redis_shared_state, :sidekiq_inline do context 'sorting', :elastic, :clean_gitlab_redis_shared_state, :sidekiq_inline do
context 'issue' do context 'issue' do
let_it_be_with_reload(:project) { create(:project, :public) }
let(:scope) { 'issues' } let(:scope) { 'issues' }
let_it_be(:project) { create(:project, :public) }
let!(:old_result) { create(:issue, project: project, title: 'sorted old', created_at: 1.month.ago) } let!(:old_result) { create(:issue, project: project, title: 'sorted old', created_at: 1.month.ago) }
let!(:new_result) { create(:issue, project: project, title: 'sorted recent', created_at: 1.day.ago) } let!(:new_result) { create(:issue, project: project, title: 'sorted recent', created_at: 1.day.ago) }
...@@ -280,8 +286,9 @@ RSpec.describe Search::GlobalService do ...@@ -280,8 +286,9 @@ RSpec.describe Search::GlobalService do
end end
context 'merge request' do context 'merge request' do
let_it_be_with_reload(:project) { create(:project, :public) }
let(:scope) { 'merge_requests' } let(:scope) { 'merge_requests' }
let(:project) { create(:project, :public) }
let!(:old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'old-1', title: 'sorted old', created_at: 1.month.ago) } let!(:old_result) { create(:merge_request, :opened, source_project: project, source_branch: 'old-1', title: 'sorted old', created_at: 1.month.ago) }
let!(:new_result) { create(:merge_request, :opened, source_project: project, source_branch: 'new-1', title: 'sorted recent', created_at: 1.day.ago) } let!(:new_result) { create(:merge_request, :opened, source_project: project, source_branch: 'new-1', title: 'sorted recent', created_at: 1.day.ago) }
...@@ -386,7 +393,7 @@ RSpec.describe Search::GlobalService do ...@@ -386,7 +393,7 @@ RSpec.describe Search::GlobalService do
end end
context 'confidential notes' do context 'confidential notes' do
let(:project) { create(:project, :public, :repository) } let_it_be(:project) { create(:project, :public, :repository) }
context 'with notes on issues' do context 'with notes on issues' do
let(:noteable) { create :issue, project: project } let(:noteable) { create :issue, project: project }
......
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