Commit 0657224a authored by Heinrich Lee Yu's avatar Heinrich Lee Yu

Merge branch '34086-genericise-index-refresh-in-specs' into 'master'

Replace Gitlab::Elastic::Helper.refresh_index

See merge request gitlab-org/gitlab!25434
parents 4c3cdf89 2e91bca6
......@@ -153,7 +153,7 @@ describe 'GlobalSearch', :elastic do
project.repository.index_commits_and_blobs
project.wiki.index_wiki_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
end
......
......@@ -17,7 +17,7 @@ describe 'Repository index', :elastic do
project.repository.create_file(user, '23', '', message: '23', branch_name: 'master')
Gitlab::Elastic::Indexer.new(project).run(sha1)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect(indexed_file_paths_for('12')).to include('12')
end
......
......@@ -16,13 +16,15 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
shared_examples 'an efficient database result' do
it 'avoids N+1 database queries' do
create(object, *creation_traits, creation_args)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
control_count = ActiveRecord::QueryRecorder.new { visit path }.count
expect(page).to have_css('.search-results') # Confirm there are search results to prevent false positives
create_list(object, 10, *creation_traits, creation_args)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
control_count = control_count + (10 * query_count_multiplier) + 1
......@@ -79,7 +81,7 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
before do
create_list(:issue, 21, project: project, title: 'initial')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it "has a pagination" do
......@@ -97,7 +99,7 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
issue = create(:issue, project: project, title: 'initial')
create_list(:note, 21, noteable: issue, project: project, note: 'foo')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it "has a pagination" do
......@@ -116,7 +118,7 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
before do
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it "finds files" do
......@@ -141,7 +143,9 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
branch_name: 'master')
project_2.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
project_2.destroy
visit dashboard_projects_path
......@@ -157,7 +161,7 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
project.wiki.create_page('test.md', '# term')
project.wiki.index_wiki_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it "finds files" do
......@@ -175,7 +179,7 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
describe 'I search through the commits' do
before do
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it "finds commits" do
......@@ -207,7 +211,7 @@ describe 'Global elastic search', :elastic, :sidekiq_inline do
describe 'I search globally', :js do
before do
create(:issue, project: project, title: 'project issue')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
visit dashboard_projects_path
......
......@@ -32,7 +32,7 @@ describe 'Group elastic search', :js, :elastic, :sidekiq_might_not_need_inline d
before do
create(:issue, project: project, title: 'chosen issue title')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'finds the issue' do
......@@ -47,7 +47,7 @@ describe 'Group elastic search', :js, :elastic, :sidekiq_might_not_need_inline d
before do
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'finds files' do
......@@ -65,7 +65,7 @@ describe 'Group elastic search', :js, :elastic, :sidekiq_might_not_need_inline d
wiki.create_page('test.md', '# term')
wiki.index_wiki_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'finds pages' do
......@@ -80,7 +80,7 @@ describe 'Group elastic search', :js, :elastic, :sidekiq_might_not_need_inline d
describe 'commit search' do
before do
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'finds commits' do
......
......@@ -24,7 +24,7 @@ describe 'Snippet elastic search', :js, :elastic, :aggregate_failures, :sidekiq_
create(:personal_snippet, :private, content: 'authorized personal snippet', author: authorized_user)
create(:project_snippet, :private, content: 'authorized project snippet', project: authorized_project)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
sign_in(current_user) if current_user
visit explore_snippets_path
......
......@@ -13,7 +13,7 @@ describe Elastic::Latest::GitClassProxy do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Indexer.new(project).run
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'returns FoundBlob', :sidekiq_inline do
......
......@@ -14,7 +14,7 @@ describe Elastic::Latest::ProjectWikiClassProxy do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Indexer.new(project, wiki: true).run
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'returns FoundWikiPage', :sidekiq_inline do
......
......@@ -76,7 +76,7 @@ describe Gitlab::Elastic::Indexer do
current_commit = project.wiki.repository.commit('master').sha
described_class.new(project, wiki: true).run(current_commit)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
def indexed_wiki_paths_for(term)
......@@ -209,7 +209,7 @@ describe Gitlab::Elastic::Indexer do
current_commit = project.repository.commit('master').sha
described_class.new(project).run(current_commit)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
def indexed_file_paths_for(term)
......
......@@ -47,7 +47,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
project1.wiki.create_page('index_page', ' term')
project1.wiki.index_wiki_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
result = described_class.new(user, 'term', project.id)
expect(result.notes_count).to eq(1)
......@@ -68,7 +68,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
project.wiki.create_page('index_page', 'term')
project.wiki.index_wiki_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
result = described_class.new(guest, 'term', project.id)
expect(result.wiki_blobs_count).to eq(1)
......@@ -153,7 +153,7 @@ describe Gitlab::Elastic::ProjectSearchResults, :elastic do
let!(:security_issue_2) { create(:issue, :confidential, title: 'Security issue 2', project: project, assignees: [assignee]) }
before do
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'does not list project confidential issues for non project members' do
......
......@@ -134,7 +134,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
iid: 2
)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it_behaves_like 'a paginated object', 'issues'
......@@ -197,7 +197,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
note: 'bar baz'
)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it_behaves_like 'a paginated object', 'notes'
......@@ -238,7 +238,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
@security_issue_4 = create(:issue, :confidential, project: project_3, title: 'Security issue 4', assignees: [assignee], iid: 1)
@security_issue_5 = create(:issue, :confidential, project: project_4, title: 'Security issue 5', iid: 1)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
context 'search by term' do
......@@ -438,7 +438,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
iid: 2
)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it_behaves_like 'a paginated object', 'merge_requests'
......@@ -503,7 +503,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
# The Milestone you have no access to
create :milestone, title: 'bla-bla term'
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
result = described_class.new(user, 'term', [project.id])
......@@ -518,7 +518,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
before do
project_1.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
def search_for(term)
......@@ -539,7 +539,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project_2 = create :project, :repository, :private
project_2.repository.index_commits_and_blobs
project_2.add_reporter(user)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
results = described_class.new(user, 'def', [project_1.id])
expect(results.blobs_count).to eq 7
......@@ -568,7 +568,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project_1.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'find by first word' do
......@@ -614,7 +614,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
before do
project_1.repository.create_file(user, file_name, file_content, message: 'Some commit message', branch_name: 'master')
project_1.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'finds files with dashes' do
......@@ -647,7 +647,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project_1.wiki.index_wiki_blobs
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it_behaves_like 'a paginated object', 'wiki_blobs'
......@@ -672,7 +672,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project_2.wiki.create_page('index_page', 'term')
project_2.wiki.index_wiki_blobs
project_2.add_guest(user)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect(results.wiki_blobs_count).to eq 1
......@@ -726,7 +726,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
describe 'Commits' do
before do
project_1.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it_behaves_like 'a paginated object', 'commits'
......@@ -743,7 +743,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project_2 = create :project, :private, :repository
project_2.repository.index_commits_and_blobs
project_2.add_reporter(user)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
results = described_class.new(user, 'add', [project_1.id])
expect(results.commits_count).to eq 24
......@@ -777,7 +777,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
issue_3 = create :issue, project: private_project2, title: "Private project where I'm a member"
issue_4 = create :issue, project: public_project, title: "Public project"
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# Authenticated search
results = described_class.new(user, 'project', limit_project_ids)
......@@ -804,7 +804,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
let!(:milestone_4) { create(:milestone, project: public_project, title: "Public project") }
before do
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it_behaves_like 'a paginated object', 'milestones'
......@@ -818,7 +818,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
public_project.project_feature.update!(merge_requests_access_level: ProjectFeature::PRIVATE)
public_project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
internal_project.project_feature.update!(issues_access_level: ProjectFeature::DISABLED)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
project_ids = user.authorized_projects.pluck(:id)
results = described_class.new(user, 'project', project_ids)
......@@ -835,7 +835,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
public_project.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
internal_project.project_feature.update!(issues_access_level: ProjectFeature::DISABLED)
internal_project.project_feature.update!(merge_requests_access_level: ProjectFeature::DISABLED)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
results = described_class.new(user, 'project', :any)
milestones = results.objects('milestones')
......@@ -905,7 +905,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
other_public_project_1 = create(:project, :public)
milestone_5 = create(:milestone, project: other_public_project_1, title: 'Public project milestone 2')
other_public_project_1.project_feature.update!(issues_access_level: ProjectFeature::PRIVATE)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
results = described_class.new(nil, 'project', [])
milestones = results.objects('milestones')
......@@ -926,7 +926,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
private_project2
public_project
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# Authenticated search
results = described_class.new(user, 'project', limit_project_ids)
......@@ -953,7 +953,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
merge_request_3 = create :merge_request, target_project: private_project2, source_project: private_project2, title: "Private project where I'm a member"
merge_request_4 = create :merge_request, target_project: public_project, source_project: public_project, title: "Public project"
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# Authenticated search
results = described_class.new(user, 'project', limit_project_ids)
......@@ -980,7 +980,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project.wiki.index_wiki_blobs
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'finds the right set of wiki blobs' do
......@@ -1014,7 +1014,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project.repository.index_commits_and_blobs
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# Authenticated search
results = described_class.new(user, 'search', limit_project_ids)
......@@ -1046,7 +1046,7 @@ describe Gitlab::Elastic::SearchResults, :elastic, :sidekiq_might_not_need_inlin
project.repository.index_commits_and_blobs
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# Authenticated search
results = described_class.new(user, 'tesla', limit_project_ids)
......
......@@ -10,7 +10,7 @@ describe Gitlab::Elastic::SnippetSearchResults, :elastic, :sidekiq_might_not_nee
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
perform_enqueued_jobs { snippet }
Snippet.__elasticsearch__.refresh_index!
ensure_elasticsearch_index!
end
describe '#snippet_titles_count' do
......
......@@ -65,7 +65,7 @@ describe Issue, :elastic do
# The issue I have no access to except as an administrator
create :issue, title: 'bla-bla term3', project: create(:project, :private)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [project.id] }
......@@ -85,7 +85,7 @@ describe Issue, :elastic do
# MergeRequest with the same iid should not be found in Issue search
create :merge_request, title: 'bla-bla', source_project: project, iid: issue.iid
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
# User needs to be admin or the MergeRequest would just be filtered by
......
......@@ -29,7 +29,7 @@ describe MergeRequest, :elastic do
# The merge request you have no access to except as an administrator
create :merge_request, title: 'also with term3', source_project: create(:project, :private)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [project.id] }
......@@ -51,7 +51,7 @@ describe MergeRequest, :elastic do
# Issue with the same iid should not be found in MergeRequest search
create :issue, project: project, iid: merge_request.iid
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [project.id] }
......
......@@ -27,7 +27,7 @@ describe Milestone, :elastic do
# The milestone you have no access to except as an administrator
create :milestone, title: 'bla-bla term3'
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [project.id] }
......
......@@ -46,7 +46,7 @@ describe Note, :elastic do
# The note in the project you have no access to except as an administrator
outside_note = create :note, note: 'bla-bla term2'
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
options = { project_ids: [issue.project.id] }
......@@ -68,7 +68,7 @@ describe Note, :elastic do
note.project.update!(visibility: Gitlab::VisibilityLevel::PUBLIC)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
project_ids = notes.map { |note| note.noteable.project.id }
......@@ -130,7 +130,7 @@ describe Note, :elastic do
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [issue.project.id] }
......@@ -145,7 +145,7 @@ describe Note, :elastic do
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [issue.project.id], current_user: user }
......@@ -160,7 +160,7 @@ describe Note, :elastic do
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [issue.project.id], current_user: superuser }
......@@ -178,7 +178,7 @@ describe Note, :elastic do
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [issue.project.id], current_user: member }
......@@ -195,7 +195,7 @@ describe Note, :elastic do
Sidekiq::Testing.inline! do
create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [issue.project.id], current_user: member }
......
......@@ -53,7 +53,7 @@ describe Project, :elastic do
create :project, path: 'test2', description: 'awesome project'
create :project
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
expect(described_class.elastic_search('test*', options: { project_ids: :any }).total_count).to eq(1)
......@@ -83,7 +83,7 @@ describe Project, :elastic do
create :project, name: 'test3', group: group
create :project, path: 'someone_elses_project', name: 'test4'
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
expect(described_class.elastic_search('test*', options: { project_ids: :any }).total_count).to eq(2)
......@@ -103,7 +103,7 @@ describe Project, :elastic do
context 'when searching with a wildcard' do
it 'only returns projects', :sidekiq_inline do
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
response = described_class.elastic_search('*')
expect(response.total_count).to eq(1)
......@@ -125,7 +125,7 @@ describe Project, :elastic do
# The project you have no access to except as an administrator
create :project, :private, name: 'test3'
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
expect(described_class.elastic_search('test1', options: { project_ids: project_ids }).total_count).to eq(1)
......@@ -144,7 +144,7 @@ describe Project, :elastic do
project1 = create :project, name: 'tesla_model_s'
project_ids += [project.id, project1.id]
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
expect(described_class.elastic_search('tesla', options: { project_ids: project_ids }).total_count).to eq(2)
......
......@@ -13,7 +13,7 @@ describe ProjectWiki, :elastic do
project.wiki.create_page("omega_page", "Bla bla term2")
project.wiki.index_wiki_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
end
......@@ -41,7 +41,7 @@ describe ProjectWiki, :elastic do
project.wiki.index_wiki_blobs(last_commit)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
expect(project.wiki.elastic_search('term2', type: :wiki_blob)[:wiki_blobs][:total_count]).to eq(0)
......
......@@ -11,7 +11,7 @@ describe Repository, :elastic do
Sidekiq::Testing.inline! do
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
end
......@@ -78,7 +78,7 @@ describe Repository, :elastic do
before do
project.repository.index_commits_and_blobs
project1.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'returns commits' do
......@@ -118,7 +118,7 @@ describe Repository, :elastic do
project = create :project, :repository
Gitlab::Elastic::Indexer.new(project).run
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect(project.repository.find_commits_by_message_with_elastic('initial').first).to be_a(Commit)
expect(project.repository.find_commits_by_message_with_elastic('initial').count).to eq(1)
......
......@@ -30,7 +30,7 @@ describe Snippet, :elastic do
let!(:project_private_snippet) { create(:snippet, :private, project: project, content: 'password: 789') }
before do
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'returns only public snippets when user is blank', :sidekiq_might_not_need_inline do
......@@ -113,7 +113,7 @@ describe Snippet, :elastic do
create(:snippet, :public, file_name: 'index.php')
create(:snippet)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { current_user: user }
......
......@@ -320,7 +320,7 @@ describe Issue do
project.maintain_elasticsearch_update
issue.update!(update_field => update_value)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
end
......
......@@ -90,7 +90,7 @@ describe Repository do
project.repository.index_commits_and_blobs
project1.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect(described_class.find_commits_by_message_with_elastic('initial').first).to be_a(Commit)
expect(described_class.find_commits_by_message_with_elastic('initial').count).to eq(2)
......@@ -103,7 +103,7 @@ describe Repository do
project = create :project, :repository
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect(project.repository.find_commits_by_message_with_elastic('initial').first).to be_a(Commit)
expect(project.repository.find_commits_by_message_with_elastic('initial').count).to eq(1)
......
......@@ -41,7 +41,7 @@ describe API::Search do
create(:wiki_page, wiki: wiki, attrs: { title: 'home', content: "Awesome page" })
project.wiki.index_wiki_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
get api(endpoint, user), params: { scope: 'wiki_blobs', search: 'awesome' }
end
......@@ -52,7 +52,7 @@ describe API::Search do
context 'for commits scope', :sidekiq_might_not_need_inline do
before do
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
get api(endpoint, user), params: { scope: 'commits', search: 'folder' }
end
......@@ -63,7 +63,7 @@ describe API::Search do
context 'for blobs scope', :sidekiq_might_not_need_inline do
before do
project.repository.index_commits_and_blobs
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
get api(endpoint, user), params: { scope: 'blobs', search: 'monitors' }
end
......
......@@ -32,7 +32,7 @@ describe Elastic::IndexRecordService, :elastic do
expect do
expect(subject.execute(object, true)).to eq(true)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end.to change { Elasticsearch::Model.search('*').records.size }.by(1)
end
......@@ -47,7 +47,7 @@ describe Elastic::IndexRecordService, :elastic do
expect do
expect(subject.execute(object, false)).to eq(true)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end.to change { Elasticsearch::Model.search('new').records.size }.by(1)
end
......@@ -84,7 +84,7 @@ describe Elastic::IndexRecordService, :elastic do
Sidekiq::Testing.inline! do
expect(subject.execute(project, true)).to eq(true)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# Fetch all child documents
children = Elasticsearch::Model.search(
......@@ -122,7 +122,7 @@ describe Elastic::IndexRecordService, :elastic do
Sidekiq::Testing.inline! do
expect(subject.execute(other_project, true)).to eq(true)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# Only the project itself should be in the index
expect(Elasticsearch::Model.search('*').total_count).to be 1
......@@ -287,7 +287,7 @@ describe Elastic::IndexRecordService, :elastic do
Sidekiq::Testing.inline! do
project = create :project, :repository, :public
note = create :note, project: project, note: 'note_1'
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
options = { project_ids: [project.id] }
......@@ -303,7 +303,7 @@ describe Elastic::IndexRecordService, :elastic do
Sidekiq::Testing.inline! do
expect(subject.execute(project, true)).to eq(true)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
expect(Note.elastic_search('note_1', options: options).present?).to eq(false)
......@@ -322,7 +322,7 @@ describe Elastic::IndexRecordService, :elastic do
Sidekiq::Testing.inline! do
expect(subject.execute(project, true)).to eq(true)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
expect(Project.elastic_search('project_1').present?).to eq(false)
......
......@@ -36,7 +36,7 @@ describe Search::GlobalService do
with_them do
it "respects visibility" do
update_feature_access_level(project, feature_access_level)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'merge_requests', expected_count: expected_count) do |user|
described_class.new(user, search: merge_request.title).execute
......@@ -61,7 +61,7 @@ describe Search::GlobalService do
it "respects visibility" do
update_feature_access_level(project, feature_access_level)
ElasticCommitIndexerWorker.new.perform(project.id)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'commits', expected_count: expected_count) do |user|
described_class.new(user, search: 'initial').execute
......@@ -89,7 +89,7 @@ describe Search::GlobalService do
with_them do
it "respects visibility" do
update_feature_access_level(project, feature_access_level)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'issues', expected_count: expected_count) do |user|
described_class.new(user, search: issue.title).execute
......@@ -114,7 +114,7 @@ describe Search::GlobalService do
project.wiki.create_page('test.md', '# term')
project.wiki.index_wiki_blobs
update_feature_access_level(project, feature_access_level)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'wiki_blobs', expected_count: expected_count) do |user|
described_class.new(user, search: 'term').execute
......@@ -136,7 +136,7 @@ describe Search::GlobalService do
'issues_access_level' => issues_access_level,
'merge_requests_access_level' => merge_requests_access_level
)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'milestones', expected_count: expected_count) do |user|
described_class.new(user, search: milestone.title).execute
......@@ -153,7 +153,7 @@ describe Search::GlobalService do
with_them do
it "respects visibility" do
ElasticCommitIndexerWorker.new.perform(project.id)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expected_objects = expected_count == 1 ? [project] : []
......
......@@ -47,7 +47,7 @@ describe Search::GroupService, :elastic do
project1, project2, project3
]
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
context 'finding projects by name', :sidekiq_might_not_need_inline do
......@@ -90,7 +90,7 @@ describe Search::GroupService, :elastic do
[project, project2].each do |project|
update_feature_access_level(project, feature_access_level)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'merge_requests', expected_count: expected_count) do |user|
described_class.new(user, group, search: merge_request.title).execute
......@@ -118,7 +118,7 @@ describe Search::GroupService, :elastic do
ElasticCommitIndexerWorker.new.perform(project.id)
end
ElasticCommitIndexerWorker.new.perform(project.id)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'commits', expected_count: expected_count) do |user|
described_class.new(user, group, search: 'initial').execute
......@@ -150,7 +150,7 @@ describe Search::GroupService, :elastic do
[project, project2].each do |project|
update_feature_access_level(project, feature_access_level)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'issues', expected_count: expected_count) do |user|
described_class.new(user, group, search: issue.title).execute
......@@ -175,7 +175,7 @@ describe Search::GroupService, :elastic do
project.wiki.create_page('test.md', '# term')
project.wiki.index_wiki_blobs
update_feature_access_level(project, feature_access_level)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'wiki_blobs', expected_count: expected_count) do |user|
described_class.new(user, project.namespace, search: 'term').execute
......@@ -197,7 +197,7 @@ describe Search::GroupService, :elastic do
'issues_access_level' => issues_access_level,
'merge_requests_access_level' => merge_requests_access_level
)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'milestones', expected_count: expected_count) do |user|
described_class.new(user, group, search: milestone.title).execute
......@@ -216,7 +216,7 @@ describe Search::GroupService, :elastic do
with_them do
it "respects visibility" do
ElasticCommitIndexerWorker.new.perform(project.id)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expected_objects = expected_count == 1 ? [project] : []
......
......@@ -40,7 +40,7 @@ describe Search::ProjectService do
[project, project2].each do |project|
update_feature_access_level(project, feature_access_level)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'merge_requests', expected_count: expected_count) do |user|
described_class.new(project, user, search: merge_request.title).execute
......@@ -69,7 +69,7 @@ describe Search::ProjectService do
update_feature_access_level(project, feature_access_level)
ElasticCommitIndexerWorker.new.perform(project.id)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'commits', expected_count: expected_count) do |user|
described_class.new(project, user, search: 'initial').execute
......@@ -101,7 +101,7 @@ describe Search::ProjectService do
[project, project2].each do |project|
update_feature_access_level(project, feature_access_level)
end
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'issues', expected_count: expected_count) do |user|
described_class.new(project, user, search: issue.title).execute
......@@ -126,7 +126,7 @@ describe Search::ProjectService do
project.wiki.create_page('test.md', '# term')
project.wiki.index_wiki_blobs
update_feature_access_level(project, feature_access_level)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'wiki_blobs', expected_count: expected_count) do |user|
described_class.new(project, user, search: 'term').execute
......@@ -148,7 +148,7 @@ describe Search::ProjectService do
'issues_access_level' => issues_access_level,
'merge_requests_access_level' => merge_requests_access_level
)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect_search_results(user, 'milestones', expected_count: expected_count) do |user|
described_class.new(project, user, search: milestone.title).execute
......
......@@ -59,7 +59,7 @@ describe Search::SnippetService do
with_them do
it "respects visibility" do
update_feature_access_level(project, feature_access_level)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expected_objects = expected_count == 0 ? [] : [snippet]
......@@ -90,7 +90,7 @@ describe Search::SnippetService do
with_them do
it "respects visibility" do
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expected_objects = expected_count == 0 ? [] : [snippet]
expect_search_results(user, 'snippet_titles', expected_objects: expected_objects) do |user|
......
......@@ -14,7 +14,7 @@ describe SearchService do
before do
stub_ee_application_setting(elasticsearch_search: true, elasticsearch_indexing: true)
Gitlab::Elastic::Indexer.new(project).run
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
# disable permission to test redaction
allow(Ability).to receive(:allowed?).and_call_original
......@@ -69,7 +69,7 @@ describe SearchService do
before do
create(:wiki_page, wiki: project.wiki)
Gitlab::Elastic::Indexer.new(project, wiki: true).run
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
end
end
......
......@@ -8,4 +8,6 @@ RSpec.configure do |config|
config.after(:each, :elastic) do
Gitlab::Elastic::Helper.delete_index
end
config.include ElasticsearchHelpers, :elastic
end
......@@ -25,7 +25,7 @@ RSpec.shared_examples 'a redacted search results page' do
create(:note_on_project_snippet, noteable: merge_request, project: public_restricted_project, note: 'A note on project snippet')
# Add to the index while the data is still public
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
# Then restrict access to that project but don't reindex so there is
......
# frozen_string_literal: true
module ElasticsearchHelpers
def ensure_elasticsearch_index!
::Gitlab::Elastic::Helper.refresh_index
end
end
......@@ -10,7 +10,7 @@ RSpec.shared_examples 'no results when the user cannot read cross project' do
expect(Ability).to receive(:allowed?).with(user, :read_cross_project) { false }
record1
record2
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end
it 'returns the record if a single project was passed', :sidekiq_might_not_need_inline do
......
......@@ -48,13 +48,13 @@ describe ElasticIndexerWorker, :elastic do
Sidekiq::Testing.disable! do
object = create(type)
subject.perform("index", name, object.id, object.es_id)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
object.destroy
end
expect do
subject.perform("delete", name, object.id, object.es_id, { 'es_parent' => object.es_parent })
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
end.to change { Elasticsearch::Model.search('*').total_count }.by(-1)
end
end
......@@ -81,13 +81,13 @@ describe ElasticIndexerWorker, :elastic do
end
ElasticCommitIndexerWorker.new.perform(project.id)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
## All database objects + data from repository. The absolute value does not matter
expect(Elasticsearch::Model.search('*').total_count).to be > 40
subject.perform("delete", "Project", project.id, project.es_id)
Gitlab::Elastic::Helper.refresh_index
ensure_elasticsearch_index!
expect(Elasticsearch::Model.search('*').total_count).to be(0)
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