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
4ccf39cd
Commit
4ccf39cd
authored
Aug 11, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix test failures, that did occur because of missing previously used `reload_status!` call
parent
6a6a69f4
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
60 additions
and
56 deletions
+60
-56
app/models/ci/build.rb
app/models/ci/build.rb
+19
-18
app/models/commit_status.rb
app/models/commit_status.rb
+8
-10
features/steps/shared/builds.rb
features/steps/shared/builds.rb
+1
-1
spec/features/pipelines_spec.rb
spec/features/pipelines_spec.rb
+7
-4
spec/lib/ci/charts_spec.rb
spec/lib/ci/charts_spec.rb
+9
-7
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+10
-14
spec/requests/api/builds_spec.rb
spec/requests/api/builds_spec.rb
+6
-2
No files found.
app/models/ci/build.rb
View file @
4ccf39cd
...
@@ -42,24 +42,25 @@ module Ci
...
@@ -42,24 +42,25 @@ module Ci
end
end
def
retry
(
build
,
user
=
nil
)
def
retry
(
build
,
user
=
nil
)
new_build
=
Ci
::
Build
.
new
(
status:
'pending'
)
new_build
=
Ci
::
Build
.
create
(
new_build
.
ref
=
build
.
ref
ref:
build
.
ref
,
new_build
.
tag
=
build
.
tag
tag:
build
.
tag
,
new_build
.
options
=
build
.
options
options:
build
.
options
,
new_build
.
commands
=
build
.
commands
commands:
build
.
commands
,
new_build
.
tag_list
=
build
.
tag_list
tag_list:
build
.
tag_list
,
new_build
.
project
=
build
.
project
project:
build
.
project
,
new_build
.
pipeline
=
build
.
pipeline
pipeline:
build
.
pipeline
,
new_build
.
name
=
build
.
name
name:
build
.
name
,
new_build
.
allow_failure
=
build
.
allow_failure
allow_failure:
build
.
allow_failure
,
new_build
.
stage
=
build
.
stage
stage:
build
.
stage
,
new_build
.
stage_idx
=
build
.
stage_idx
stage_idx:
build
.
stage_idx
,
new_build
.
trigger_request
=
build
.
trigger_request
trigger_request:
build
.
trigger_request
,
new_build
.
yaml_variables
=
build
.
yaml_variables
yaml_variables:
build
.
yaml_variables
,
new_build
.
when
=
build
.
when
when:
build
.
when
,
new_build
.
user
=
user
user:
user
,
new_build
.
environment
=
build
.
environment
environment:
build
.
environment
,
new_build
.
save
status_event:
'queue'
)
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
build
.
project
,
nil
).
close
(
new_build
)
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
build
.
project
,
nil
).
close
(
new_build
)
new_build
new_build
end
end
...
...
app/models/commit_status.rb
View file @
4ccf39cd
...
@@ -62,14 +62,6 @@ class CommitStatus < ActiveRecord::Base
...
@@ -62,14 +62,6 @@ class CommitStatus < ActiveRecord::Base
commit_status
.
update_attributes
finished_at:
Time
.
now
commit_status
.
update_attributes
finished_at:
Time
.
now
end
end
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
commit_status
|
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
trigger
(
commit_status
)
end
after_transition
any
=>
:failed
do
|
commit_status
|
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
execute
(
commit_status
)
end
# We use around_transition to process pipeline on next stages as soon as possible, before the `after_*` is executed
# We use around_transition to process pipeline on next stages as soon as possible, before the `after_*` is executed
around_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
commit_status
,
block
|
around_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
commit_status
,
block
|
block
.
call
block
.
call
...
@@ -77,11 +69,17 @@ class CommitStatus < ActiveRecord::Base
...
@@ -77,11 +69,17 @@ class CommitStatus < ActiveRecord::Base
commit_status
.
pipeline
.
try
(
:process!
)
commit_status
.
pipeline
.
try
(
:process!
)
end
end
# Try to update the pipeline status
after_transition
do
|
commit_status
,
transition
|
after_transition
do
|
commit_status
,
transition
|
commit_status
.
pipeline
.
try
(
:update_status
)
unless
transition
.
loopback?
commit_status
.
pipeline
.
try
(
:update_status
)
unless
transition
.
loopback?
end
end
after_transition
[
:created
,
:pending
,
:running
]
=>
:success
do
|
commit_status
|
MergeRequests
::
MergeWhenBuildSucceedsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
trigger
(
commit_status
)
end
after_transition
any
=>
:failed
do
|
commit_status
|
MergeRequests
::
AddTodoWhenBuildFailsService
.
new
(
commit_status
.
pipeline
.
project
,
nil
).
execute
(
commit_status
)
end
end
end
delegate
:sha
,
:short_sha
,
to: :pipeline
delegate
:sha
,
:short_sha
,
to: :pipeline
...
...
features/steps/shared/builds.rb
View file @
4ccf39cd
...
@@ -23,7 +23,7 @@ module SharedBuilds
...
@@ -23,7 +23,7 @@ module SharedBuilds
end
end
step
'project has another build that is running'
do
step
'project has another build that is running'
do
create
(
:ci_build
,
pipeline:
@pipeline
,
name:
'second build'
,
status
:
'running
'
)
create
(
:ci_build
,
pipeline:
@pipeline
,
name:
'second build'
,
status
_event:
'run
'
)
end
end
step
'I visit recent build details page'
do
step
'I visit recent build details page'
do
...
...
spec/features/pipelines_spec.rb
View file @
4ccf39cd
...
@@ -12,7 +12,7 @@ describe "Pipelines" do
...
@@ -12,7 +12,7 @@ describe "Pipelines" do
end
end
describe
'GET /:project/pipelines'
do
describe
'GET /:project/pipelines'
do
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
ref:
'master'
,
status:
'running'
)
}
let!
(
:pipeline
)
{
create
(
:ci_
empty_
pipeline
,
project:
project
,
ref:
'master'
,
status:
'running'
)
}
[
:all
,
:running
,
:branches
].
each
do
|
scope
|
[
:all
,
:running
,
:branches
].
each
do
|
scope
|
context
"displaying
#{
scope
}
"
do
context
"displaying
#{
scope
}
"
do
...
@@ -31,9 +31,10 @@ describe "Pipelines" do
...
@@ -31,9 +31,10 @@ describe "Pipelines" do
end
end
context
'cancelable pipeline'
do
context
'cancelable pipeline'
do
let!
(
:
running
)
{
create
(
:ci_build
,
:running
,
pipeline:
pipeline
,
stage:
'test'
,
commands:
'test'
)
}
let!
(
:
build
)
{
create
(
:ci_build
,
pipeline:
pipeline
,
stage:
'test'
,
commands:
'test'
)
}
before
do
before
do
build
.
run
visit
namespace_project_pipelines_path
(
project
.
namespace
,
project
)
visit
namespace_project_pipelines_path
(
project
.
namespace
,
project
)
end
end
...
@@ -49,9 +50,10 @@ describe "Pipelines" do
...
@@ -49,9 +50,10 @@ describe "Pipelines" do
end
end
context
'retryable pipelines'
do
context
'retryable pipelines'
do
let!
(
:
failed
)
{
create
(
:ci_build
,
:faile
d
,
pipeline:
pipeline
,
stage:
'test'
,
commands:
'test'
)
}
let!
(
:
build
)
{
create
(
:ci_buil
d
,
pipeline:
pipeline
,
stage:
'test'
,
commands:
'test'
)
}
before
do
before
do
build
.
drop
visit
namespace_project_pipelines_path
(
project
.
namespace
,
project
)
visit
namespace_project_pipelines_path
(
project
.
namespace
,
project
)
end
end
...
@@ -98,9 +100,10 @@ describe "Pipelines" do
...
@@ -98,9 +100,10 @@ describe "Pipelines" do
end
end
context
'when failed'
do
context
'when failed'
do
let!
(
:
failed
)
{
create
(
:generic_commit_status
,
status:
'failed'
,
pipeline:
pipeline
,
stage:
'test'
)
}
let!
(
:
status
)
{
create
(
:generic_commit_status
,
:pending
,
pipeline:
pipeline
,
stage:
'test'
)
}
before
do
before
do
status
.
drop
visit
namespace_project_pipelines_path
(
project
.
namespace
,
project
)
visit
namespace_project_pipelines_path
(
project
.
namespace
,
project
)
end
end
...
...
spec/lib/ci/charts_spec.rb
View file @
4ccf39cd
...
@@ -2,21 +2,23 @@ require 'spec_helper'
...
@@ -2,21 +2,23 @@ require 'spec_helper'
describe
Ci
::
Charts
,
lib:
true
do
describe
Ci
::
Charts
,
lib:
true
do
context
"build_times"
do
context
"build_times"
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:chart
)
{
Ci
::
Charts
::
BuildTime
.
new
(
project
)
}
subject
{
chart
.
build_times
}
before
do
before
do
@pipeline
=
FactoryGirl
.
create
(
:ci_pipeline
)
create
(
:ci_empty_pipeline
,
project:
project
,
duration:
120
)
FactoryGirl
.
create
(
:ci_build
,
pipeline:
@pipeline
)
end
end
it
'returns build times in minutes'
do
it
'returns build times in minutes'
do
chart
=
Ci
::
Charts
::
BuildTime
.
new
(
@pipeline
.
project
)
is_expected
.
to
contain_exactly
(
2
)
expect
(
chart
.
build_times
).
to
eq
([
2
])
end
end
it
'handles nil build times'
do
it
'handles nil build times'
do
create
(
:ci_
pipeline
,
duration:
nil
,
project:
@pipeline
.
project
)
create
(
:ci_
empty_pipeline
,
project:
project
,
duration:
nil
)
chart
=
Ci
::
Charts
::
BuildTime
.
new
(
@pipeline
.
project
)
is_expected
.
to
contain_exactly
(
2
,
0
)
expect
(
chart
.
build_times
).
to
eq
([
2
,
0
])
end
end
end
end
end
end
spec/models/ci/pipeline_spec.rb
View file @
4ccf39cd
...
@@ -120,22 +120,18 @@ describe Ci::Pipeline, models: true do
...
@@ -120,22 +120,18 @@ describe Ci::Pipeline, models: true do
end
end
end
end
describe
'#update_counters'
do
describe
'#duration'
do
let
(
:pipeline
)
{
create
:ci_empty_pipeline
,
project:
project
}
let
(
:current
)
{
Time
.
now
.
change
(
usec:
0
)
}
let!
(
:build
)
{
create
:ci_build
,
name:
'build1'
,
pipeline:
pipeline
,
started_at:
current
-
60
,
finished_at:
current
}
let!
(
:build2
)
{
create
:ci_build
,
name:
'build2'
,
pipeline:
pipeline
,
started_at:
current
-
60
,
finished_at:
current
}
context
'updates'
do
before
do
let
(
:current
)
{
Time
.
now
.
change
(
usec:
0
)
}
build
.
skip
let
(
:build
)
{
FactoryGirl
.
create
:ci_build
,
pipeline:
pipeline
,
started_at:
current
-
120
,
finished_at:
current
-
60
}
build2
.
skip
end
before
do
build
.
skip
end
[
:status
,
:started_at
,
:finished_at
,
:duration
].
each
do
|
param
|
it
'matches sum of builds duration'
do
it
"
#{
param
}
"
do
expect
(
pipeline
.
reload
.
duration
).
to
eq
(
build
.
duration
+
build2
.
duration
)
expect
(
pipeline
.
reload
.
send
(
param
)).
to
eq
(
build
.
send
(
param
))
end
end
end
end
end
end
...
...
spec/requests/api/builds_spec.rb
View file @
4ccf39cd
...
@@ -9,7 +9,7 @@ describe API::API, api: true do
...
@@ -9,7 +9,7 @@ describe API::API, api: true do
let!
(
:developer
)
{
create
(
:project_member
,
:developer
,
user:
user
,
project:
project
)
}
let!
(
:developer
)
{
create
(
:project_member
,
:developer
,
user:
user
,
project:
project
)
}
let
(
:reporter
)
{
create
(
:project_member
,
:reporter
,
project:
project
)
}
let
(
:reporter
)
{
create
(
:project_member
,
:reporter
,
project:
project
)
}
let
(
:guest
)
{
create
(
:project_member
,
:guest
,
project:
project
)
}
let
(
:guest
)
{
create
(
:project_member
,
:guest
,
project:
project
)
}
let!
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
}
let!
(
:pipeline
)
{
create
(
:ci_
empty_
pipeline
,
project:
project
,
sha:
project
.
commit
.
id
,
ref:
project
.
default_branch
)
}
let!
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let!
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
describe
'GET /projects/:id/builds '
do
describe
'GET /projects/:id/builds '
do
...
@@ -174,7 +174,11 @@ describe API::API, api: true do
...
@@ -174,7 +174,11 @@ describe API::API, api: true do
describe
'GET /projects/:id/artifacts/:ref_name/download?job=name'
do
describe
'GET /projects/:id/artifacts/:ref_name/download?job=name'
do
let
(
:api_user
)
{
reporter
.
user
}
let
(
:api_user
)
{
reporter
.
user
}
let
(
:build
)
{
create
(
:ci_build
,
:success
,
:artifacts
,
pipeline:
pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
:artifacts
,
pipeline:
pipeline
)
}
before
do
build
.
success
end
def
path_for_ref
(
ref
=
pipeline
.
ref
,
job
=
build
.
name
)
def
path_for_ref
(
ref
=
pipeline
.
ref
,
job
=
build
.
name
)
api
(
"/projects/
#{
project
.
id
}
/builds/artifacts/
#{
ref
}
/download?job=
#{
job
}
"
,
api_user
)
api
(
"/projects/
#{
project
.
id
}
/builds/artifacts/
#{
ref
}
/download?job=
#{
job
}
"
,
api_user
)
...
...
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