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
Boxiang Sun
gitlab-ce
Commits
ad3e1edc
Commit
ad3e1edc
authored
Aug 12, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added specs for started_at and finished_at
parent
e1f05b93
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
46 additions
and
15 deletions
+46
-15
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+8
-7
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+38
-8
No files found.
app/models/ci/pipeline.rb
View file @
ad3e1edc
...
@@ -22,10 +22,11 @@ module Ci
...
@@ -22,10 +22,11 @@ module Ci
state_machine
:status
,
initial: :created
do
state_machine
:status
,
initial: :created
do
event
:queue
do
event
:queue
do
transition
:created
=>
:pending
transition
:created
=>
:pending
transition
any
-
[
:created
,
:pending
]
=>
:running
end
end
event
:run
do
event
:run
do
transition
[
:pending
,
:success
,
:failed
,
:canceled
,
:skipped
]
=>
:running
transition
any
=>
:running
end
end
event
:skip
do
event
:skip
do
...
@@ -44,15 +45,15 @@ module Ci
...
@@ -44,15 +45,15 @@ module Ci
transition
any
=>
:canceled
transition
any
=>
:canceled
end
end
after
_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
before
_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
pipeline
.
update
(
started_at:
Time
.
now
)
pipeline
.
started_at
=
Time
.
now
end
end
after
_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
pipeline
|
before
_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
pipeline
|
pipeline
.
update
(
finished_at:
Time
.
now
)
pipeline
.
finished_at
=
Time
.
now
end
end
after
_transition
do
|
pipeline
|
before
_transition
do
|
pipeline
|
pipeline
.
update_duration
pipeline
.
update_duration
end
end
end
end
...
@@ -245,7 +246,7 @@ module Ci
...
@@ -245,7 +246,7 @@ module Ci
end
end
def
update_duration
def
update_duration
update
(
duration:
statuses
.
latest
.
duration
)
self
.
duration
=
statuses
.
latest
.
duration
end
end
private
private
...
...
spec/models/ci/pipeline_spec.rb
View file @
ad3e1edc
...
@@ -120,18 +120,48 @@ describe Ci::Pipeline, models: true do
...
@@ -120,18 +120,48 @@ describe Ci::Pipeline, models: true do
end
end
end
end
describe
'
#duration
'
do
describe
'
state machine
'
do
let
(
:current
)
{
Time
.
now
.
change
(
usec:
0
)
}
let
(
:current
)
{
Time
.
now
.
change
(
usec:
0
)
}
let
!
(
:build
)
{
create
:ci_build
,
name:
'build1'
,
pipeline:
pipeline
,
started_at:
current
-
60
,
finished_at:
current
}
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
}
let
(
:build2
)
{
create
:ci_build
,
name:
'build2'
,
pipeline:
pipeline
,
started_at:
current
-
60
,
finished_at:
current
}
before
do
describe
'#duration'
do
build
.
skip
before
do
build2
.
skip
build
.
skip
build2
.
skip
end
it
'matches sum of builds duration'
do
expect
(
pipeline
.
reload
.
duration
).
to
eq
(
build
.
duration
+
build2
.
duration
)
end
end
end
it
'matches sum of builds duration'
do
describe
'#started_at'
do
expect
(
pipeline
.
reload
.
duration
).
to
eq
(
build
.
duration
+
build2
.
duration
)
it
'updates on transitioning to running'
do
build
.
run
expect
(
pipeline
.
reload
.
started_at
).
not_to
be_nil
end
it
'do not update on transitioning to success'
do
build
.
success
expect
(
pipeline
.
reload
.
started_at
).
to
be_nil
end
end
describe
'#finished_at'
do
it
'updates on transitioning to success'
do
build
.
success
expect
(
pipeline
.
reload
.
finished_at
).
not_to
be_nil
end
it
'do not update on transitioning to running'
do
build
.
run
expect
(
pipeline
.
reload
.
finished_at
).
to
be_nil
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