Commit 5bb583bf authored by Rémy Coutable's avatar Rémy Coutable

Merge branch '37725-pipeline-junit-view-performance-on-running-on-big-data-set' into 'master'

Add new endpoint for pipeline badge counter

See merge request gitlab-org/gitlab!24319
parents 7fc536b5 aee04884
......@@ -179,6 +179,16 @@ class Projects::PipelinesController < Projects::ApplicationController
end
end
def test_reports_count
return unless Feature.enabled?(:junit_pipeline_view, project)
begin
render json: { total_count: pipeline.test_reports_count }.to_json
rescue Gitlab::Ci::Parsers::ParserError
render json: { total_count: 0 }.to_json
end
end
private
def serialize_pipelines
......
......@@ -789,6 +789,12 @@ module Ci
end
end
def test_reports_count
Rails.cache.fetch(['project', project.id, 'pipeline', id, 'test_reports_count'], force: false) do
test_reports.total_count
end
end
def has_exposed_artifacts?
complete? && builds.latest.with_exposed_artifacts.exists?
end
......
......@@ -341,6 +341,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get :failures
get :status
get :test_report
get :test_reports_count
end
member do
......
......@@ -682,6 +682,76 @@ describe Projects::PipelinesController do
end
end
describe 'GET test_report_count.json' do
subject(:test_reports_count_json) do
get :test_reports_count, params: {
namespace_id: project.namespace,
project_id: project,
id: pipeline.id
},
format: :json
end
context 'when feature is enabled' do
before do
stub_feature_flags(junit_pipeline_view: true)
end
context 'when pipeline does not have a test report' do
let(:pipeline) { create(:ci_pipeline, project: project) }
it 'renders an empty badge counter' do
test_reports_count_json
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['total_count']).to eq(0)
end
end
context 'when pipeline has a test report' do
let(:pipeline) { create(:ci_pipeline, :with_test_reports, project: project) }
it 'renders the badge counter value' do
test_reports_count_json
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['total_count']).to eq(4)
end
end
context 'when pipeline has corrupt test reports' do
let(:pipeline) { create(:ci_pipeline, project: project) }
before do
job = create(:ci_build, pipeline: pipeline)
create(:ci_job_artifact, :junit_with_corrupted_data, job: job, project: project)
end
it 'renders 0' do
test_reports_count_json
expect(response).to have_gitlab_http_status(:ok)
expect(json_response['total_count']).to eq(0)
end
end
end
context 'when feature is disabled' do
let(:pipeline) { create(:ci_empty_pipeline, project: project) }
before do
stub_feature_flags(junit_pipeline_view: false)
end
it 'renders empty response' do
test_reports_count_json
expect(response).to have_gitlab_http_status(:no_content)
expect(response.body).to be_empty
end
end
end
describe 'GET latest' do
let(:branch_main) { project.repository.branches[0] }
let(:branch_secondary) { project.repository.branches[1] }
......
......@@ -2678,6 +2678,40 @@ describe Ci::Pipeline, :mailer do
end
end
describe '#test_reports_count', :use_clean_rails_memory_store_caching do
subject { pipeline.test_reports }
context 'when pipeline has multiple builds with test reports' do
let!(:build_rspec) { create(:ci_build, :success, name: 'rspec', pipeline: pipeline, project: project) }
let!(:build_java) { create(:ci_build, :success, name: 'java', pipeline: pipeline, project: project) }
before do
create(:ci_job_artifact, :junit, job: build_rspec, project: project)
create(:ci_job_artifact, :junit_with_ant, job: build_java, project: project)
end
it 'returns test report count equal to test reports total_count' do
expect(subject.total_count).to eq(7)
expect(subject.total_count).to eq(pipeline.test_reports_count)
end
it 'reads from cache when records are cached' do
expect(Rails.cache.fetch(['project', project.id, 'pipeline', pipeline.id, 'test_reports_count'], force: false)).to be_nil
pipeline.test_reports_count
expect(ActiveRecord::QueryRecorder.new { pipeline.test_reports_count }.count).to eq(0)
end
end
context 'when pipeline does not have any builds with test reports' do
it 'returns empty test report count' do
expect(subject.total_count).to eq(0)
expect(subject.total_count).to eq(pipeline.test_reports_count)
end
end
end
describe '#total_size' do
let!(:build_job1) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
let!(:build_job2) { create(:ci_build, pipeline: pipeline, stage_idx: 0) }
......
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