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
39204d8c
Commit
39204d8c
authored
Sep 15, 2018
by
Markus Doits
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactor retry logic to define any reason and more than one reason to retry
parent
007db85d
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
27 additions
and
110 deletions
+27
-110
app/models/ci/build.rb
app/models/ci/build.rb
+4
-9
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+23
-101
No files found.
app/models/ci/build.rb
View file @
39204d8c
...
...
@@ -324,20 +324,15 @@ module Ci
def
retry_when
retries
=
self
.
options
[
:retry
]
retries
.
is_a?
(
Hash
)
&&
retries
.
fetch
(
:when
,
'always'
).
to_s
||
'always'
Array
.
wrap
(
retries
.
is_a?
(
Hash
)
&&
retries
.
fetch
(
:when
,
'always'
)
||
'always'
)
end
def
retry_failure?
return
false
if
retries_max
.
zero?
||
retries_count
>=
retries_max
case
failure_reason
.
to_s
when
'runner_system_failure'
%['always', 'system failure']
.
include?
(
retry_when
)
when
'script_failure'
%['always', 'script failure']
.
include?
(
retry_when
)
else
retry_when
==
'always'
end
retry_when
.
include?
(
'always'
)
||
retry_when
.
include?
(
failure_reason
.
to_s
)
end
def
latest?
...
...
spec/models/ci/build_spec.rb
View file @
39204d8c
...
...
@@ -1514,11 +1514,19 @@ describe Ci::Build do
end
describe
'#retry_when'
do
context
'when value is defined'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
{
when: :something
}
})
}
context
'when value is defined without an array'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
{
when:
'something'
}
})
}
it
'returns the configured value inside an array'
do
expect
(
subject
.
retry_when
).
to
eq
[
'something'
]
end
end
context
'when value is defined without as an array'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
{
when:
%w[something more]
}
})
}
it
'returns the configured value'
do
expect
(
subject
.
retry_when
).
to
eq
:something
expect
(
subject
.
retry_when
).
to
eq
%w[something more]
end
end
...
...
@@ -1526,7 +1534,7 @@ describe Ci::Build do
subject
{
create
(
:ci_build
)
}
it
'returns `always`'
do
expect
(
subject
.
retry_when
).
to
eq
:always
expect
(
subject
.
retry_when
).
to
eq
[
'always'
]
end
end
...
...
@@ -1534,7 +1542,7 @@ describe Ci::Build do
subject
{
create
(
:ci_build
,
options:
{
retry:
1
})
}
it
'returns `always`'
do
expect
(
subject
.
retry_when
).
to
eq
:always
expect
(
subject
.
retry_when
).
to
eq
[
'always'
]
end
end
end
...
...
@@ -1579,111 +1587,25 @@ describe Ci::Build do
end
end
context
'and failure was a system runner failure'
do
before
do
expect
(
subject
).
to
receive
(
:failure_reason
).
at_least
(
:once
).
and_return
(
'runner_system_failure'
)
end
context
'and retry when is always'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'always'
)
end
it
'returns true'
do
expect
(
subject
.
retry_failure?
).
to
eq
true
end
end
context
'and retry when is system failure'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'system failure'
)
end
it
'returns true'
do
expect
(
subject
.
retry_failure?
).
to
eq
true
end
end
context
'and retry when is script failure'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'script failure'
)
end
it
'returns false'
do
expect
(
subject
.
retry_failure?
).
to
eq
false
end
end
end
context
'and failure was a script failure'
do
context
'and retry when includes the failure_reason'
do
before
do
expect
(
subject
).
to
receive
(
:failure_reason
).
at_least
(
:once
).
and_return
(
'script_failure'
)
end
context
'and retry when is always'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'always'
)
end
it
'returns true'
do
expect
(
subject
.
retry_failure?
).
to
eq
true
end
end
context
'and retry when is system failure'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'system failure'
)
end
it
'returns false'
do
expect
(
subject
.
retry_failure?
).
to
eq
false
end
expect
(
subject
).
to
receive
(
:failure_reason
).
at_least
(
:once
).
and_return
(
'some_reason'
)
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
([
'some_reason'
])
end
context
'and retry when is script failure'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'script failure'
)
end
it
'returns true'
do
expect
(
subject
.
retry_failure?
).
to
eq
true
end
it
'returns true'
do
expect
(
subject
.
retry_failure?
).
to
eq
true
end
end
context
'and
failure was some other failure
'
do
context
'and
retry when does not include failure_reason
'
do
before
do
expect
(
subject
).
to
receive
(
:failure_reason
).
at_least
(
:once
).
and_return
(
'some other reason'
)
end
context
'and retry when is always'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'always'
)
end
it
'returns true'
do
expect
(
subject
.
retry_failure?
).
to
eq
true
end
expect
(
subject
).
to
receive
(
:failure_reason
).
at_least
(
:once
).
and_return
(
'some_reason'
)
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
([
'some'
,
'other failure'
])
end
context
'and retry when is system failure'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'system failure'
)
end
it
'returns false'
do
expect
(
subject
.
retry_failure?
).
to
eq
false
end
end
context
'and retry when is script failure'
do
before
do
expect
(
subject
).
to
receive
(
:retry_when
).
at_least
(
:once
).
and_return
(
'script failure'
)
end
it
'returns false'
do
expect
(
subject
.
retry_failure?
).
to
eq
false
end
it
'returns false'
do
expect
(
subject
.
retry_failure?
).
to
eq
false
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