Commit ca8b260a authored by Rubén Dávila Santos's avatar Rubén Dávila Santos

Merge branch 'fix-elastic-search-specs' into 'master'

Run Sidekiq in inline mode for Elastic Search related specs



See merge request !652
parents cf1076a5 6deb952e
...@@ -14,14 +14,16 @@ describe Issue, elastic: true do ...@@ -14,14 +14,16 @@ describe Issue, elastic: true do
it "searches issues" do it "searches issues" do
project = create :empty_project project = create :empty_project
create :issue, title: 'bla-bla term', project: project Sidekiq::Testing.inline! do
create :issue, description: 'bla-bla term', project: project create :issue, title: 'bla-bla term', project: project
create :issue, project: project create :issue, description: 'bla-bla term', project: project
create :issue, project: project
# The issue I have no access to # The issue I have no access to
create :issue, title: 'bla-bla term' create :issue, title: 'bla-bla term'
Gitlab::Elastic::Helper.refresh_index Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [project.id] } options = { project_ids: [project.id] }
......
...@@ -14,14 +14,16 @@ describe Milestone, elastic: true do ...@@ -14,14 +14,16 @@ describe Milestone, elastic: true do
it "searches milestones" do it "searches milestones" do
project = create :empty_project project = create :empty_project
create :milestone, title: 'bla-bla term', project: project Sidekiq::Testing.inline! do
create :milestone, description: 'bla-bla term', project: project create :milestone, title: 'bla-bla term', project: project
create :milestone, project: project create :milestone, description: 'bla-bla term', project: project
create :milestone, project: project
# The milestone you have no access to # The milestone you have no access to
create :milestone, title: 'bla-bla term' create :milestone, title: 'bla-bla term'
Gitlab::Elastic::Helper.refresh_index Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [project.id] } options = { project_ids: [project.id] }
......
...@@ -14,13 +14,15 @@ describe Note, elastic: true do ...@@ -14,13 +14,15 @@ describe Note, elastic: true do
it "searches notes" do it "searches notes" do
issue = create :issue issue = create :issue
create :note, note: 'bla-bla term', project: issue.project Sidekiq::Testing.inline! do
create :note, project: issue.project create :note, note: 'bla-bla term', project: issue.project
create :note, project: issue.project
# The note in the project you have no access to # The note in the project you have no access to
create :note, note: 'bla-bla term' create :note, note: 'bla-bla term'
Gitlab::Elastic::Helper.refresh_index Gitlab::Elastic::Helper.refresh_index
end
options = { project_ids: [issue.project.id] } options = { project_ids: [issue.project.id] }
...@@ -56,10 +58,10 @@ describe Note, elastic: true do ...@@ -56,10 +58,10 @@ describe Note, elastic: true do
it "does not find note" do it "does not find note" do
issue = create :issue, :confidential issue = create :issue, :confidential
create :note, note: 'bla-bla term', project: issue.project, noteable: issue Sidekiq::Testing.inline! do
create :note, project: issue.project, noteable: issue create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
Gitlab::Elastic::Helper.refresh_index end
options = { project_ids: [issue.project.id] } options = { project_ids: [issue.project.id] }
...@@ -70,10 +72,10 @@ describe Note, elastic: true do ...@@ -70,10 +72,10 @@ describe Note, elastic: true do
user = create :user user = create :user
issue = create :issue, :confidential, author: user issue = create :issue, :confidential, author: user
create :note, note: 'bla-bla term', project: issue.project, noteable: issue Sidekiq::Testing.inline! do
create :note, project: issue.project, noteable: issue create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
Gitlab::Elastic::Helper.refresh_index end
options = { project_ids: [issue.project.id], current_user: user } options = { project_ids: [issue.project.id], current_user: user }
...@@ -87,10 +89,10 @@ describe Note, elastic: true do ...@@ -87,10 +89,10 @@ describe Note, elastic: true do
member = create(:user) member = create(:user)
issue.project.team << [member, :developer] issue.project.team << [member, :developer]
create :note, note: 'bla-bla term', project: issue.project, noteable: issue Sidekiq::Testing.inline! do
create :note, project: issue.project, noteable: issue create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
Gitlab::Elastic::Helper.refresh_index end
options = { project_ids: [issue.project.id], current_user: member } options = { project_ids: [issue.project.id], current_user: member }
...@@ -104,14 +106,19 @@ describe Note, elastic: true do ...@@ -104,14 +106,19 @@ describe Note, elastic: true do
member = create(:user) member = create(:user)
issue.project.team << [member, :guest] issue.project.team << [member, :guest]
create :note, note: 'bla-bla term', project: issue.project, noteable: issue Sidekiq::Testing.inline! do
create :note, project: issue.project, noteable: issue create_notes_for(issue, 'bla-bla term')
Gitlab::Elastic::Helper.refresh_index
Gitlab::Elastic::Helper.refresh_index end
options = { project_ids: [issue.project.id], current_user: member } options = { project_ids: [issue.project.id], current_user: member }
expect(Note.elastic_search('term', options: options).total_count).to eq(0) expect(Note.elastic_search('term', options: options).total_count).to eq(0)
end end
end end
def create_notes_for(issue, note)
create :note, note: note, project: issue.project, noteable: issue
create :note, project: issue.project, noteable: issue
end
end end
...@@ -12,13 +12,17 @@ describe Project, elastic: true do ...@@ -12,13 +12,17 @@ describe Project, elastic: true do
end end
it "searches projects" do it "searches projects" do
project = create :empty_project, name: 'test' project_ids = []
project1 = create :empty_project, path: 'test1'
project2 = create :empty_project
create :empty_project, path: 'someone_elses_project'
project_ids = [project.id, project1.id, project2.id]
Gitlab::Elastic::Helper.refresh_index Sidekiq::Testing.inline! do
project = create :empty_project, name: 'test'
project1 = create :empty_project, path: 'test1'
project2 = create :empty_project
create :empty_project, path: 'someone_elses_project'
project_ids += [project.id, project1.id, project2.id]
Gitlab::Elastic::Helper.refresh_index
end
expect(described_class.elastic_search('test', options: { pids: project_ids }).total_count).to eq(1) expect(described_class.elastic_search('test', options: { pids: project_ids }).total_count).to eq(1)
expect(described_class.elastic_search('test1', options: { pids: project_ids }).total_count).to eq(1) expect(described_class.elastic_search('test1', options: { pids: project_ids }).total_count).to eq(1)
......
...@@ -14,10 +14,12 @@ describe Repository, elastic: true do ...@@ -14,10 +14,12 @@ describe Repository, elastic: true do
it "searches blobs and commits" do it "searches blobs and commits" do
project = create :project project = create :project
project.repository.index_blobs Sidekiq::Testing.inline! do
project.repository.index_commits project.repository.index_blobs
project.repository.index_commits
Gitlab::Elastic::Helper.refresh_index Gitlab::Elastic::Helper.refresh_index
end
expect(project.repository.search('def popen')[:blobs][:total_count]).to eq(1) expect(project.repository.search('def popen')[:blobs][:total_count]).to eq(1)
expect(project.repository.search('initial')[:commits][:total_count]).to eq(1) expect(project.repository.search('initial')[:commits][:total_count]).to eq(1)
......
...@@ -73,12 +73,14 @@ describe Snippet, elastic: true do ...@@ -73,12 +73,14 @@ describe Snippet, elastic: true do
it 'searches snippets by title and file_name' do it 'searches snippets by title and file_name' do
user = create(:user) user = create(:user)
create(:snippet, :public, title: 'home') Sidekiq::Testing.inline! do
create(:snippet, :private, title: 'home 1') create(:snippet, :public, title: 'home')
create(:snippet, :public, file_name: 'index.php') create(:snippet, :private, title: 'home 1')
create(:snippet) create(:snippet, :public, file_name: 'index.php')
create(:snippet)
Gitlab::Elastic::Helper.refresh_index Gitlab::Elastic::Helper.refresh_index
end
options = { user: user } options = { user: user }
......
...@@ -14,11 +14,12 @@ describe ProjectWiki, elastic: true do ...@@ -14,11 +14,12 @@ describe ProjectWiki, elastic: true do
it "searches wiki page" do it "searches wiki page" do
project = create :empty_project project = create :empty_project
project.wiki.create_page("index_page", "Bla bla") Sidekiq::Testing.inline! do
project.wiki.create_page("index_page", "Bla bla")
project.wiki.index_blobs
project.wiki.index_blobs Gitlab::Elastic::Helper.refresh_index
end
Gitlab::Elastic::Helper.refresh_index
expect(project.wiki.search('bla', type: :blob)[:blobs][:total_count]).to eq(1) expect(project.wiki.search('bla', type: :blob)[:blobs][:total_count]).to eq(1)
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