Commit 09118796 authored by Matija Čupić's avatar Matija Čupić

Add N+1 query spec for Jobs API

parent c9840842
...@@ -25,8 +25,10 @@ describe API::Jobs do ...@@ -25,8 +25,10 @@ describe API::Jobs do
describe 'GET /projects/:id/jobs' do describe 'GET /projects/:id/jobs' do
let(:query) { Hash.new } let(:query) { Hash.new }
before do before do |example|
get api("/projects/#{project.id}/jobs", api_user), query unless example.metadata[:skip_before_request]
get api("/projects/#{project.id}/jobs", api_user), query
end
end end
context 'authorized user' do context 'authorized user' do
...@@ -51,6 +53,12 @@ describe API::Jobs do ...@@ -51,6 +53,12 @@ describe API::Jobs do
expect(json_job['pipeline']['status']).to eq job.pipeline.status expect(json_job['pipeline']['status']).to eq job.pipeline.status
end end
it 'avoids N+1 queries', skip_before_request: true do
control_count = ActiveRecord::QueryRecorder.new { go }.count
create_list(:ci_build, 5, pipeline: pipeline)
expect { go }.not_to exceed_query_limit(control_count)
end
context 'filter project with one scope element' do context 'filter project with one scope element' do
let(:query) { { 'scope' => 'pending' } } let(:query) { { 'scope' => 'pending' } }
...@@ -83,6 +91,9 @@ describe API::Jobs do ...@@ -83,6 +91,9 @@ describe API::Jobs do
expect(response).to have_gitlab_http_status(401) expect(response).to have_gitlab_http_status(401)
end end
end end
def go
get api("/projects/#{project.id}/jobs", api_user), query
end
end end
describe 'GET /projects/:id/pipelines/:pipeline_id/jobs' do describe 'GET /projects/:id/pipelines/:pipeline_id/jobs' 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