Commit 4bca92dd authored by Maxime Orefice's avatar Maxime Orefice Committed by Robert Speicher

Expose tests total count in PipelineEntity

parent e0e69938
...@@ -85,6 +85,10 @@ class PipelineEntity < Grape::Entity ...@@ -85,6 +85,10 @@ class PipelineEntity < Grape::Entity
pipeline.failed_builds pipeline.failed_builds
end end
expose :tests_total_count, if: -> (pipeline, _) { Feature.enabled?(:build_report_summary, pipeline.project) } do |pipeline|
pipeline.test_report_summary.total_count
end
private private
alias_method :pipeline, :object alias_method :pipeline, :object
......
...@@ -46,7 +46,7 @@ RSpec.describe Projects::PipelinesController do ...@@ -46,7 +46,7 @@ RSpec.describe Projects::PipelinesController do
end end
end end
it 'does not execute N+1 queries' do it 'executes N+1 queries' do
get_pipelines_index_json get_pipelines_index_json
control_count = ActiveRecord::QueryRecorder.new do control_count = ActiveRecord::QueryRecorder.new do
...@@ -56,10 +56,31 @@ RSpec.describe Projects::PipelinesController do ...@@ -56,10 +56,31 @@ RSpec.describe Projects::PipelinesController do
create_all_pipeline_types create_all_pipeline_types
# There appears to be one extra query for Pipelines#has_warnings? for some reason # There appears to be one extra query for Pipelines#has_warnings? for some reason
expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 1) expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 7)
expect(response).to have_gitlab_http_status(:ok) expect(response).to have_gitlab_http_status(:ok)
expect(json_response['pipelines'].count).to eq 12 expect(json_response['pipelines'].count).to eq 12
end end
context 'with build_report_summary turned off' do
before do
stub_feature_flags(build_report_summary: false)
end
it 'does not execute N+1 queries' do
get_pipelines_index_json
control_count = ActiveRecord::QueryRecorder.new do
get_pipelines_index_json
end.count
create_all_pipeline_types
# There appears to be one extra query for Pipelines#has_warnings? for some reason
expect { get_pipelines_index_json }.not_to exceed_query_limit(control_count + 1)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['pipelines'].count).to eq 12
end
end
end end
it 'does not include coverage data for the pipelines' do it 'does not include coverage data for the pipelines' do
......
...@@ -261,5 +261,29 @@ RSpec.describe PipelineEntity do ...@@ -261,5 +261,29 @@ RSpec.describe PipelineEntity do
end end
end end
end end
context 'when pipeline has build report results' do
let(:pipeline) { create(:ci_pipeline, :with_report_results, project: project, user: user) }
context 'when feature is enabled' do
before do
stub_feature_flags(build_report_summary: true)
end
it 'exposes tests total count' do
expect(subject[:tests_total_count]).to eq(2)
end
end
context 'when feature is disabled' do
before do
stub_feature_flags(build_report_summary: false)
end
it 'do not expose tests total count' do
expect(subject).not_to include(:tests_total_count)
end
end
end
end end
end end
...@@ -155,11 +155,25 @@ RSpec.describe PipelineSerializer do ...@@ -155,11 +155,25 @@ RSpec.describe PipelineSerializer do
it 'verifies number of queries', :request_store do it 'verifies number of queries', :request_store do
recorded = ActiveRecord::QueryRecorder.new { subject } recorded = ActiveRecord::QueryRecorder.new { subject }
expected_queries = Gitlab.ee? ? 43 : 40 expected_queries = Gitlab.ee? ? 46 : 43
expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0) expect(recorded.cached_count).to eq(0)
end end
context 'with the :build_report_summary flag turned off' do
before do
stub_feature_flags(build_report_summary: false)
end
it 'verifies number of queries', :request_store do
recorded = ActiveRecord::QueryRecorder.new { subject }
expected_queries = Gitlab.ee? ? 43 : 40
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
end
end
end end
context 'with different refs' do context 'with different refs' do
...@@ -176,11 +190,25 @@ RSpec.describe PipelineSerializer do ...@@ -176,11 +190,25 @@ RSpec.describe PipelineSerializer do
# pipeline. With the same ref this check is cached but if refs are # pipeline. With the same ref this check is cached but if refs are
# different then there is an extra query per ref # different then there is an extra query per ref
# https://gitlab.com/gitlab-org/gitlab-foss/issues/46368 # https://gitlab.com/gitlab-org/gitlab-foss/issues/46368
expected_queries = Gitlab.ee? ? 46 : 43 expected_queries = Gitlab.ee? ? 49 : 46
expect(recorded.count).to be_within(2).of(expected_queries) expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0) expect(recorded.cached_count).to eq(0)
end end
context 'with the :build_report_summary flag turned off' do
before do
stub_feature_flags(build_report_summary: false)
end
it 'verifies number of queries', :request_store do
recorded = ActiveRecord::QueryRecorder.new { subject }
expected_queries = Gitlab.ee? ? 46 : 43
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
end
end
end end
def create_pipeline(status) def create_pipeline(status)
......
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