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
0
Merge Requests
0
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
Tatuya Kamada
gitlab-ce
Commits
ebd5ced7
Commit
ebd5ced7
authored
Oct 20, 2016
by
James Lopez
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added test events specs and logic. Also fixed some SQL and refactored the pipeline worker spec.
parent
52e2729b
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
55 additions
and
10 deletions
+55
-10
app/models/merge_request.rb
app/models/merge_request.rb
+1
-1
lib/gitlab/cycle_analytics/events.rb
lib/gitlab/cycle_analytics/events.rb
+7
-0
lib/gitlab/cycle_analytics/events_fetcher.rb
lib/gitlab/cycle_analytics/events_fetcher.rb
+13
-1
spec/lib/gitlab/cycle_analytics/events_spec.rb
spec/lib/gitlab/cycle_analytics/events_spec.rb
+23
-1
spec/workers/pipeline_metrics_worker_spec.rb
spec/workers/pipeline_metrics_worker_spec.rb
+11
-7
No files found.
app/models/merge_request.rb
View file @
ebd5ced7
...
@@ -232,7 +232,7 @@ class MergeRequest < ActiveRecord::Base
...
@@ -232,7 +232,7 @@ class MergeRequest < ActiveRecord::Base
end
end
def
diff_head_commit
def
diff_head_commit
if
persisted?
diff_head_commit
if
persisted?
merge_request_diff
.
head_commit
merge_request_diff
.
head_commit
else
else
source_branch_head
source_branch_head
...
...
lib/gitlab/cycle_analytics/events.rb
View file @
ebd5ced7
...
@@ -34,6 +34,13 @@ module Gitlab
...
@@ -34,6 +34,13 @@ module Gitlab
end
end
end
end
def
test_events
@fetcher
.
fetch_test_events
.
each
do
|
event
|
event
[
'total_time'
]
=
distance_of_time_in_words
(
event
[
'total_time'
].
to_f
)
event
[
'pipeline'
]
=
::
Ci
::
Pipeline
.
find_by_id
(
event
[
'ci_commit_id'
])
# we may not have a pipeline
end
end
private
private
def
first_time_reference_commit
(
commits
,
event
)
def
first_time_reference_commit
(
commits
,
event
)
...
...
lib/gitlab/cycle_analytics/events_fetcher.rb
View file @
ebd5ced7
...
@@ -36,7 +36,7 @@ module Gitlab
...
@@ -36,7 +36,7 @@ module Gitlab
base_query
=
base_query_for
(
:code
)
base_query
=
base_query_for
(
:code
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
diff_fn
=
subtract_datetimes_diff
(
base_query
,
issue_metrics_table
[
:first_mentioned_in_commit_at
],
issue_metrics_table
[
:first_mentioned_in_commit_at
],
issue
_table
[
:created_at
])
mr
_table
[
:created_at
])
query
=
base_query
.
join
(
user_table
).
on
(
issue_table
[
:author_id
].
eq
(
user_table
[
:id
])).
query
=
base_query
.
join
(
user_table
).
on
(
issue_table
[
:author_id
].
eq
(
user_table
[
:id
])).
project
(
extract_epoch
(
diff_fn
).
as
(
'total_time'
),
*
code_projections
).
project
(
extract_epoch
(
diff_fn
).
as
(
'total_time'
),
*
code_projections
).
...
@@ -45,6 +45,18 @@ module Gitlab
...
@@ -45,6 +45,18 @@ module Gitlab
execute
(
query
)
execute
(
query
)
end
end
def
fetch_test_events
base_query
=
base_query_for
(
:code
)
diff_fn
=
subtract_datetimes_diff
(
base_query
,
mr_metrics_table
[
:latest_build_started_at
],
mr_metrics_table
[
:latest_build_finished_at
])
query
=
base_query
.
project
(
extract_epoch
(
diff_fn
).
as
(
'total_time'
),
mr_metrics_table
[
:ci_commit_id
]).
order
(
mr_table
[
:created_at
].
desc
)
execute
(
query
)
end
private
private
def
issue_attributes
def
issue_attributes
...
...
spec/lib/gitlab/cycle_analytics/events_spec.rb
View file @
ebd5ced7
...
@@ -55,7 +55,7 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -55,7 +55,7 @@ describe Gitlab::CycleAnalytics::Events do
end
end
it
'has the total time'
do
it
'has the total time'
do
expect
(
subject
.
code_events
.
first
[
'total_time'
]).
to
eq
(
'
2 days
'
)
expect
(
subject
.
code_events
.
first
[
'total_time'
]).
to
eq
(
'
less than a minute
'
)
end
end
it
'has a title'
do
it
'has a title'
do
...
@@ -75,6 +75,28 @@ describe Gitlab::CycleAnalytics::Events do
...
@@ -75,6 +75,28 @@ describe Gitlab::CycleAnalytics::Events do
end
end
end
end
describe
'#test_events'
do
let!
(
:context
)
{
create
(
:issue
,
project:
project
,
created_at:
2
.
days
.
ago
)
}
let
(
:merge_request
)
{
MergeRequest
.
first
}
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
ref:
merge_request
.
source_branch
,
sha:
merge_request
.
diff_head_sha
,
project:
context
.
project
)
}
before
do
pipeline
.
run!
pipeline
.
succeed!
end
it
'has the build info as a pipeline'
do
expect
(
subject
.
test_events
.
first
[
'pipeline'
]).
to
eq
(
pipeline
)
end
it
'has the total time'
do
expect
(
subject
.
test_events
.
first
[
'total_time'
]).
to
eq
(
'less than a minute'
)
end
end
def
setup
(
context
)
def
setup
(
context
)
milestone
=
create
(
:milestone
,
project:
project
)
milestone
=
create
(
:milestone
,
project:
project
)
context
.
update
(
milestone:
milestone
)
context
.
update
(
milestone:
milestone
)
...
...
spec/workers/pipeline_metrics_worker_spec.rb
View file @
ebd5ced7
...
@@ -15,32 +15,36 @@ describe PipelineMetricsWorker do
...
@@ -15,32 +15,36 @@ describe PipelineMetricsWorker do
end
end
describe
'#perform'
do
describe
'#perform'
do
subject
{
described_class
.
new
.
perform
(
pipeline
.
id
)
}
before
do
described_class
.
new
.
perform
(
pipeline
.
id
)
end
context
'when pipeline is running'
do
context
'when pipeline is running'
do
let
(
:status
)
{
'running'
}
let
(
:status
)
{
'running'
}
it
'records the build start time'
do
it
'records the build start time'
do
subject
expect
(
merge_request
.
reload
.
metrics
.
latest_build_started_at
).
to
be_like_time
(
pipeline
.
started_at
)
expect
(
merge_request
.
reload
.
metrics
.
latest_build_started_at
).
to
be_like_time
(
pipeline
.
started_at
)
end
end
it
'clears the build end time'
do
it
'clears the build end time'
do
subject
expect
(
merge_request
.
reload
.
metrics
.
latest_build_finished_at
).
to
be_nil
expect
(
merge_request
.
reload
.
metrics
.
latest_build_finished_at
).
to
be_nil
end
end
it
'records the pipeline'
do
expect
(
merge_request
.
reload
.
metrics
.
pipeline
).
to
eq
(
pipeline
)
end
end
end
context
'when pipeline succeeded'
do
context
'when pipeline succeeded'
do
let
(
:status
)
{
'success'
}
let
(
:status
)
{
'success'
}
it
'records the build end time'
do
it
'records the build end time'
do
subject
expect
(
merge_request
.
reload
.
metrics
.
latest_build_finished_at
).
to
be_like_time
(
pipeline
.
finished_at
)
expect
(
merge_request
.
reload
.
metrics
.
latest_build_finished_at
).
to
be_like_time
(
pipeline
.
finished_at
)
end
end
it
'records the pipeline'
do
expect
(
merge_request
.
reload
.
metrics
.
pipeline
).
to
eq
(
pipeline
)
end
end
end
end
end
end
end
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