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
ce641335
Commit
ce641335
authored
Aug 15, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Introduce Gitlab::Utils.now so that it's easier to stub
parent
0ea81ae5
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
15 additions
and
7 deletions
+15
-7
app/models/ci/pipeline.rb
app/models/ci/pipeline.rb
+2
-2
app/models/concerns/statuseable.rb
app/models/concerns/statuseable.rb
+1
-1
lib/gitlab/utils.rb
lib/gitlab/utils.rb
+6
-1
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+6
-3
No files found.
app/models/ci/pipeline.rb
View file @
ce641335
...
@@ -48,11 +48,11 @@ module Ci
...
@@ -48,11 +48,11 @@ module Ci
end
end
before_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
before_transition
[
:created
,
:pending
]
=>
:running
do
|
pipeline
|
pipeline
.
started_at
=
Time
.
now
pipeline
.
started_at
=
Gitlab
::
Utils
.
now
end
end
before_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
pipeline
|
before_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
pipeline
|
pipeline
.
finished_at
=
Time
.
now
pipeline
.
finished_at
=
Gitlab
::
Utils
.
now
end
end
before_transition
do
|
pipeline
|
before_transition
do
|
pipeline
|
...
...
app/models/concerns/statuseable.rb
View file @
ce641335
...
@@ -87,7 +87,7 @@ module Statuseable
...
@@ -87,7 +87,7 @@ module Statuseable
if
started_at
&&
finished_at
if
started_at
&&
finished_at
finished_at
-
started_at
finished_at
-
started_at
elsif
started_at
elsif
started_at
Time
.
now
-
started_at
Gitlab
::
Utils
.
now
-
started_at
end
end
end
end
end
end
lib/gitlab/utils.rb
View file @
ce641335
...
@@ -7,11 +7,16 @@ module Gitlab
...
@@ -7,11 +7,16 @@ module Gitlab
# @param cmd [Array<String>]
# @param cmd [Array<String>]
# @return [Boolean]
# @return [Boolean]
def
system_silent
(
cmd
)
def
system_silent
(
cmd
)
Popen
::
popen
(
cmd
).
last
.
zero?
Popen
.
popen
(
cmd
).
last
.
zero?
end
end
def
force_utf8
(
str
)
def
force_utf8
(
str
)
str
.
force_encoding
(
Encoding
::
UTF_8
)
str
.
force_encoding
(
Encoding
::
UTF_8
)
end
end
# The same as Time.now but using this would make it easier to test
def
now
Time
.
now
end
end
end
end
end
spec/models/ci/pipeline_spec.rb
View file @
ce641335
...
@@ -129,12 +129,15 @@ describe Ci::Pipeline, models: true do
...
@@ -129,12 +129,15 @@ describe Ci::Pipeline, models: true do
describe
'#duration'
do
describe
'#duration'
do
before
do
before
do
build
.
skip
allow
(
Gitlab
::
Utils
).
to
receive
(
:now
).
build2
.
skip
and_return
(
current
-
120
,
current
)
pipeline
.
run
pipeline
.
succeed
end
end
it
'matches sum of builds duration'
do
it
'matches sum of builds duration'
do
expect
(
pipeline
.
reload
.
duration
).
to
eq
(
build
.
duration
+
build2
.
duration
)
expect
(
pipeline
.
reload
.
duration
).
to
eq
(
120
)
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