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
dd1c410e
Commit
dd1c410e
authored
Jan 29, 2017
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Reduce the number of loops that Cycle Analytics specs use
See
https://gitlab.com/gitlab-org/gitlab-ce/issues/27402
parent
b525aff6
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
72 additions
and
102 deletions
+72
-102
spec/models/cycle_analytics/code_spec.rb
spec/models/cycle_analytics/code_spec.rb
+9
-13
spec/models/cycle_analytics/issue_spec.rb
spec/models/cycle_analytics/issue_spec.rb
+5
-7
spec/models/cycle_analytics/production_spec.rb
spec/models/cycle_analytics/production_spec.rb
+7
-11
spec/models/cycle_analytics/review_spec.rb
spec/models/cycle_analytics/review_spec.rb
+1
-3
spec/models/cycle_analytics/staging_spec.rb
spec/models/cycle_analytics/staging_spec.rb
+7
-11
spec/models/cycle_analytics/test_spec.rb
spec/models/cycle_analytics/test_spec.rb
+21
-29
spec/support/cycle_analytics_helpers/test_generation.rb
spec/support/cycle_analytics_helpers/test_generation.rb
+22
-28
No files found.
spec/models/cycle_analytics/code_spec.rb
View file @
dd1c410e
...
@@ -27,15 +27,13 @@ describe 'CycleAnalytics#code', feature: true do
...
@@ -27,15 +27,13 @@ describe 'CycleAnalytics#code', feature: true do
context
"when a regular merge request (that doesn't close the issue) is created"
do
context
"when a regular merge request (that doesn't close the issue) is created"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
create_commit_referencing_issue
(
issue
)
create_commit_referencing_issue
(
issue
)
create_merge_request_closing_issue
(
issue
,
message:
"Closes nothing"
)
create_merge_request_closing_issue
(
issue
,
message:
"Closes nothing"
)
merge_merge_requests_closing_issue
(
issue
)
merge_merge_requests_closing_issue
(
issue
)
deploy_master
deploy_master
end
expect
(
subject
[
:code
].
median
).
to
be_nil
expect
(
subject
[
:code
].
median
).
to
be_nil
end
end
...
@@ -60,14 +58,12 @@ describe 'CycleAnalytics#code', feature: true do
...
@@ -60,14 +58,12 @@ describe 'CycleAnalytics#code', feature: true do
context
"when a regular merge request (that doesn't close the issue) is created"
do
context
"when a regular merge request (that doesn't close the issue) is created"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
create_commit_referencing_issue
(
issue
)
create_commit_referencing_issue
(
issue
)
create_merge_request_closing_issue
(
issue
,
message:
"Closes nothing"
)
create_merge_request_closing_issue
(
issue
,
message:
"Closes nothing"
)
merge_merge_requests_closing_issue
(
issue
)
merge_merge_requests_closing_issue
(
issue
)
end
expect
(
subject
[
:code
].
median
).
to
be_nil
expect
(
subject
[
:code
].
median
).
to
be_nil
end
end
...
...
spec/models/cycle_analytics/issue_spec.rb
View file @
dd1c410e
...
@@ -33,14 +33,12 @@ describe 'CycleAnalytics#issue', models: true do
...
@@ -33,14 +33,12 @@ describe 'CycleAnalytics#issue', models: true do
context
"when a regular label (instead of a list label) is added to the issue"
do
context
"when a regular label (instead of a list label) is added to the issue"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
regular_label
=
create
(
:label
)
regular_label
=
create
(
:label
)
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
issue
.
update
(
label_ids:
[
regular_label
.
id
])
issue
.
update
(
label_ids:
[
regular_label
.
id
])
create_merge_request_closing_issue
(
issue
)
create_merge_request_closing_issue
(
issue
)
merge_merge_requests_closing_issue
(
issue
)
merge_merge_requests_closing_issue
(
issue
)
end
expect
(
subject
[
:issue
].
median
).
to
be_nil
expect
(
subject
[
:issue
].
median
).
to
be_nil
end
end
...
...
spec/models/cycle_analytics/production_spec.rb
View file @
dd1c410e
...
@@ -29,11 +29,9 @@ describe 'CycleAnalytics#production', feature: true do
...
@@ -29,11 +29,9 @@ describe 'CycleAnalytics#production', feature: true do
context
"when a regular merge request (that doesn't close the issue) is merged and deployed"
do
context
"when a regular merge request (that doesn't close the issue) is merged and deployed"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
merge_request
=
create
(
:merge_request
)
merge_request
=
create
(
:merge_request
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
deploy_master
deploy_master
end
expect
(
subject
[
:production
].
median
).
to
be_nil
expect
(
subject
[
:production
].
median
).
to
be_nil
end
end
...
@@ -41,12 +39,10 @@ describe 'CycleAnalytics#production', feature: true do
...
@@ -41,12 +39,10 @@ describe 'CycleAnalytics#production', feature: true do
context
"when the deployment happens to a non-production environment"
do
context
"when the deployment happens to a non-production environment"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
deploy_master
(
environment:
'staging'
)
deploy_master
(
environment:
'staging'
)
end
expect
(
subject
[
:production
].
median
).
to
be_nil
expect
(
subject
[
:production
].
median
).
to
be_nil
end
end
...
...
spec/models/cycle_analytics/review_spec.rb
View file @
dd1c410e
...
@@ -23,9 +23,7 @@ describe 'CycleAnalytics#review', feature: true do
...
@@ -23,9 +23,7 @@ describe 'CycleAnalytics#review', feature: true do
context
"when a regular merge request (that doesn't close the issue) is created and merged"
do
context
"when a regular merge request (that doesn't close the issue) is created and merged"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
create
(
:merge_request
))
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
create
(
:merge_request
))
end
expect
(
subject
[
:review
].
median
).
to
be_nil
expect
(
subject
[
:review
].
median
).
to
be_nil
end
end
...
...
spec/models/cycle_analytics/staging_spec.rb
View file @
dd1c410e
...
@@ -40,11 +40,9 @@ describe 'CycleAnalytics#staging', feature: true do
...
@@ -40,11 +40,9 @@ describe 'CycleAnalytics#staging', feature: true do
context
"when a regular merge request (that doesn't close the issue) is merged and deployed"
do
context
"when a regular merge request (that doesn't close the issue) is merged and deployed"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
merge_request
=
create
(
:merge_request
)
merge_request
=
create
(
:merge_request
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
deploy_master
deploy_master
end
expect
(
subject
[
:staging
].
median
).
to
be_nil
expect
(
subject
[
:staging
].
median
).
to
be_nil
end
end
...
@@ -52,12 +50,10 @@ describe 'CycleAnalytics#staging', feature: true do
...
@@ -52,12 +50,10 @@ describe 'CycleAnalytics#staging', feature: true do
context
"when the deployment happens to a non-production environment"
do
context
"when the deployment happens to a non-production environment"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
MergeRequests
::
MergeService
.
new
(
project
,
user
).
execute
(
merge_request
)
deploy_master
(
environment:
'staging'
)
deploy_master
(
environment:
'staging'
)
end
expect
(
subject
[
:staging
].
median
).
to
be_nil
expect
(
subject
[
:staging
].
median
).
to
be_nil
end
end
...
...
spec/models/cycle_analytics/test_spec.rb
View file @
dd1c410e
...
@@ -24,16 +24,14 @@ describe 'CycleAnalytics#test', feature: true do
...
@@ -24,16 +24,14 @@ describe 'CycleAnalytics#test', feature: true do
context
"when the pipeline is for a regular merge request (that doesn't close an issue)"
do
context
"when the pipeline is for a regular merge request (that doesn't close an issue)"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
.
run!
pipeline
.
run!
pipeline
.
succeed!
pipeline
.
succeed!
merge_merge_requests_closing_issue
(
issue
)
merge_merge_requests_closing_issue
(
issue
)
end
expect
(
subject
[
:test
].
median
).
to
be_nil
expect
(
subject
[
:test
].
median
).
to
be_nil
end
end
...
@@ -41,12 +39,10 @@ describe 'CycleAnalytics#test', feature: true do
...
@@ -41,12 +39,10 @@ describe 'CycleAnalytics#test', feature: true do
context
"when the pipeline is not for a merge request"
do
context
"when the pipeline is not for a merge request"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/master"
,
sha:
project
.
repository
.
commit
(
'master'
).
sha
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/master"
,
sha:
project
.
repository
.
commit
(
'master'
).
sha
)
pipeline
.
run!
pipeline
.
run!
pipeline
.
succeed!
pipeline
.
succeed!
end
expect
(
subject
[
:test
].
median
).
to
be_nil
expect
(
subject
[
:test
].
median
).
to
be_nil
end
end
...
@@ -54,16 +50,14 @@ describe 'CycleAnalytics#test', feature: true do
...
@@ -54,16 +50,14 @@ describe 'CycleAnalytics#test', feature: true do
context
"when the pipeline is dropped (failed)"
do
context
"when the pipeline is dropped (failed)"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
.
run!
pipeline
.
run!
pipeline
.
drop!
pipeline
.
drop!
merge_merge_requests_closing_issue
(
issue
)
merge_merge_requests_closing_issue
(
issue
)
end
expect
(
subject
[
:test
].
median
).
to
be_nil
expect
(
subject
[
:test
].
median
).
to
be_nil
end
end
...
@@ -71,16 +65,14 @@ describe 'CycleAnalytics#test', feature: true do
...
@@ -71,16 +65,14 @@ describe 'CycleAnalytics#test', feature: true do
context
"when the pipeline is cancelled"
do
context
"when the pipeline is cancelled"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
issue
=
create
(
:issue
,
project:
project
)
issue
=
create
(
:issue
,
project:
project
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
merge_request
=
create_merge_request_closing_issue
(
issue
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
=
create
(
:ci_pipeline
,
ref:
"refs/heads/
#{
merge_request
.
source_branch
}
"
,
sha:
merge_request
.
diff_head_sha
)
pipeline
.
run!
pipeline
.
run!
pipeline
.
cancel!
pipeline
.
cancel!
merge_merge_requests_closing_issue
(
issue
)
merge_merge_requests_closing_issue
(
issue
)
end
expect
(
subject
[
:test
].
median
).
to
be_nil
expect
(
subject
[
:test
].
median
).
to
be_nil
end
end
...
...
spec/support/cycle_analytics_helpers/test_generation.rb
View file @
dd1c410e
...
@@ -63,22 +63,20 @@ module CycleAnalyticsHelpers
...
@@ -63,22 +63,20 @@ module CycleAnalyticsHelpers
# test case.
# test case.
allow
(
self
).
to
receive
(
:project
)
{
other_project
}
allow
(
self
).
to
receive
(
:project
)
{
other_project
}
5
.
times
do
data
=
data_fn
[
self
]
data
=
data_fn
[
self
]
start_time
=
Time
.
now
start_time
=
Time
.
now
end_time
=
rand
(
1
..
10
).
days
.
from_now
end_time
=
rand
(
1
..
10
).
days
.
from_now
start_time_conditions
.
each
do
|
condition_name
,
condition_fn
|
Timecop
.
freeze
(
start_time
)
{
condition_fn
[
self
,
data
]
}
end
end
_time_conditions
.
each
do
|
condition_name
,
condition_fn
|
start
_time_conditions
.
each
do
|
condition_name
,
condition_fn
|
Timecop
.
freeze
(
end
_time
)
{
condition_fn
[
self
,
data
]
}
Timecop
.
freeze
(
start
_time
)
{
condition_fn
[
self
,
data
]
}
end
end
Timecop
.
freeze
(
end_time
+
1
.
day
)
{
post_fn
[
self
,
data
]
}
if
post_fn
end_time_conditions
.
each
do
|
condition_name
,
condition_fn
|
Timecop
.
freeze
(
end_time
)
{
condition_fn
[
self
,
data
]
}
end
end
Timecop
.
freeze
(
end_time
+
1
.
day
)
{
post_fn
[
self
,
data
]
}
if
post_fn
# Turn off the stub before checking assertions
# Turn off the stub before checking assertions
allow
(
self
).
to
receive
(
:project
).
and_call_original
allow
(
self
).
to
receive
(
:project
).
and_call_original
...
@@ -114,17 +112,15 @@ module CycleAnalyticsHelpers
...
@@ -114,17 +112,15 @@ module CycleAnalyticsHelpers
context
"start condition NOT PRESENT:
#{
start_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
context
"start condition NOT PRESENT:
#{
start_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
context
"end condition:
#{
end_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
context
"end condition:
#{
end_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
data
=
data_fn
[
self
]
data
=
data_fn
[
self
]
end_time
=
rand
(
1
..
10
).
days
.
from_now
end_time
=
rand
(
1
..
10
).
days
.
from_now
end_time_conditions
.
each_with_index
do
|
(
condition_name
,
condition_fn
),
index
|
Timecop
.
freeze
(
end_time
+
index
.
days
)
{
condition_fn
[
self
,
data
]
}
end
Timecop
.
freeze
(
end_time
+
1
.
day
)
{
post_fn
[
self
,
data
]
}
if
post_fn
end_time_conditions
.
each_with_index
do
|
(
condition_name
,
condition_fn
),
index
|
Timecop
.
freeze
(
end_time
+
index
.
days
)
{
condition_fn
[
self
,
data
]
}
end
end
Timecop
.
freeze
(
end_time
+
1
.
day
)
{
post_fn
[
self
,
data
]
}
if
post_fn
expect
(
subject
[
phase
].
median
).
to
be_nil
expect
(
subject
[
phase
].
median
).
to
be_nil
end
end
end
end
...
@@ -133,17 +129,15 @@ module CycleAnalyticsHelpers
...
@@ -133,17 +129,15 @@ module CycleAnalyticsHelpers
context
"start condition:
#{
start_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
context
"start condition:
#{
start_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
context
"end condition NOT PRESENT:
#{
end_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
context
"end condition NOT PRESENT:
#{
end_time_conditions
.
map
(
&
:first
).
to_sentence
}
"
do
it
"returns nil"
do
it
"returns nil"
do
5
.
times
do
data
=
data_fn
[
self
]
data
=
data_fn
[
self
]
start_time
=
Time
.
now
start_time
=
Time
.
now
start_time_conditions
.
each
do
|
condition_name
,
condition_fn
|
Timecop
.
freeze
(
start_time
)
{
condition_fn
[
self
,
data
]
}
end
post_fn
[
self
,
data
]
if
post_fn
start_time_conditions
.
each
do
|
condition_name
,
condition_fn
|
Timecop
.
freeze
(
start_time
)
{
condition_fn
[
self
,
data
]
}
end
end
post_fn
[
self
,
data
]
if
post_fn
expect
(
subject
[
phase
].
median
).
to
be_nil
expect
(
subject
[
phase
].
median
).
to
be_nil
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