Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
aee04884
Commit
aee04884
authored
Feb 11, 2020
by
Maxime Orefice
Committed by
Rémy Coutable
Feb 11, 2020
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Cache total_count value for test suite
- One step to improve performance of junit view
parent
ec46fc91
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
121 additions
and
0 deletions
+121
-0
app/controllers/projects/pipelines_controller.rb
app/controllers/projects/pipelines_controller.rb
+10
-0
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+6
-0
config/routes/project.rb
config/routes/project.rb
+1
-0
spec/controllers/projects/pipelines_controller_spec.rb
spec/controllers/projects/pipelines_controller_spec.rb
+70
-0
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+34
-0
No files found.
app/controllers/projects/pipelines_controller.rb
View file @
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
...
...
app/models/ci/pipeline.rb
View file @
aee04884
...
...
@@ -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
...
...
config/routes/project.rb
View file @
aee04884
...
...
@@ -341,6 +341,7 @@ constraints(::Constraints::ProjectUrlConstrainer.new) do
get
:failures
get
:status
get
:test_report
get
:test_reports_count
end
member
do
...
...
spec/controllers/projects/pipelines_controller_spec.rb
View file @
aee04884
...
...
@@ -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
]
}
...
...
spec/models/ci/pipeline_spec.rb
View file @
aee04884
...
...
@@ -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
)
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment