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
pipeline.failed_builds
end
expose :tests_total_count, if: -> (pipeline, _) { Feature.enabled?(:build_report_summary, pipeline.project) } do |pipeline|
pipeline.test_report_summary.total_count
end
private
alias_method :pipeline, :object
......
......@@ -46,6 +46,26 @@ RSpec.describe Projects::PipelinesController do
end
end
it 'executes 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 + 7)
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['pipelines'].count).to eq 12
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
......@@ -61,6 +81,7 @@ RSpec.describe Projects::PipelinesController do
expect(json_response['pipelines'].count).to eq 12
end
end
end
it 'does not include coverage data for the pipelines' do
get_pipelines_index_json
......
......@@ -261,5 +261,29 @@ RSpec.describe PipelineEntity do
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
......@@ -153,6 +153,19 @@ RSpec.describe PipelineSerializer do
context 'with the same ref' do
let(:ref) { 'feature' }
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
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
......@@ -161,6 +174,7 @@ RSpec.describe PipelineSerializer do
expect(recorded.cached_count).to eq(0)
end
end
end
context 'with different refs' do
def ref
......@@ -176,12 +190,26 @@ RSpec.describe PipelineSerializer do
# pipeline. With the same ref this check is cached but if refs are
# different then there is an extra query per ref
# https://gitlab.com/gitlab-org/gitlab-foss/issues/46368
expected_queries = Gitlab.ee? ? 49 : 46
expect(recorded.count).to be_within(2).of(expected_queries)
expect(recorded.cached_count).to eq(0)
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
def create_pipeline(status)
create(:ci_empty_pipeline,
......
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