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
9818bb56
Commit
9818bb56
authored
Oct 19, 2018
by
Markus Doits
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
refactoring after latest feedback
parent
ff3484a0
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
137 additions
and
106 deletions
+137
-106
app/models/ci/build.rb
app/models/ci/build.rb
+2
-6
lib/gitlab/ci/config/entry/retry.rb
lib/gitlab/ci/config/entry/retry.rb
+15
-1
spec/lib/gitlab/ci/config/entry/retry_spec.rb
spec/lib/gitlab/ci/config/entry/retry_spec.rb
+111
-58
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+9
-41
No files found.
app/models/ci/build.rb
View file @
9818bb56
...
...
@@ -318,15 +318,11 @@ module Ci
end
def
retries_max
retries
=
self
.
options
[
:retry
]
retries
.
is_a?
(
Hash
)
&&
retries
.
fetch
(
:max
,
0
)
||
retries
||
0
options
&
.
dig
(
:retry
,
:max
)
||
0
end
def
retry_when
retries
=
self
.
options
[
:retry
]
Array
.
wrap
(
retries
.
is_a?
(
Hash
)
&&
retries
.
fetch
(
:when
,
'always'
)
||
'always'
)
options
&
.
dig
(
:retry
,
:when
)
||
[
'always'
]
end
def
retry_failure?
...
...
lib/gitlab/ci/config/entry/retry.rb
View file @
9818bb56
...
...
@@ -18,6 +18,12 @@ module Gitlab
less_than_or_equal_to:
2
}
end
def
value
{
max:
config
}
end
def
location
'retry'
end
...
...
@@ -49,7 +55,15 @@ module Gitlab
end
def
self
.
possible_retry_when_values
@possible_retry_when_values
||=
Gitlab
::
Ci
::
Status
::
Build
::
Failed
.
reasons
.
keys
.
map
(
&
:to_s
)
+
[
'always'
]
@possible_retry_when_values
||=
CommitStatus
.
failure_reasons
.
keys
.
map
(
&
:to_s
)
+
[
'always'
]
end
def
value
super
.
tap
do
|
config
|
# make sure that `when` is an array, because we allow it to
# be passed as a String in config for simplicity
config
[
:when
]
=
Array
.
wrap
(
config
[
:when
])
if
config
[
:when
]
end
end
def
location
...
...
spec/lib/gitlab/ci/config/entry/retry_spec.rb
View file @
9818bb56
...
...
@@ -3,42 +3,84 @@ require 'spec_helper'
describe
Gitlab
::
Ci
::
Config
::
Entry
::
Retry
do
let
(
:entry
)
{
described_class
.
new
(
config
)
}
shared_context
'when retry value is a numeric'
,
:numeric
do
let
(
:config
)
{
max
}
let
(
:max
)
{}
end
shared_context
'when retry value is a hash'
,
:hash
do
let
(
:config
)
{
{
max:
max
,
when:
public_send
(
:when
)
}.
compact
}
let
(
:when
)
{}
let
(
:max
)
{}
end
describe
'#value'
do
subject
(
:value
)
{
entry
.
value
}
context
'when retry value is a numeric'
,
:numeric
do
let
(
:max
)
{
2
}
it
'is returned as a hash with max key'
do
expect
(
value
).
to
eq
(
max:
2
)
end
end
context
'when retry value is a hash'
,
:hash
do
context
'and `when` is a string'
do
let
(
:when
)
{
'unknown_failure'
}
it
'returns when wrapped in an array'
do
expect
(
value
).
to
eq
(
when:
[
'unknown_failure'
])
end
end
context
'and `when` is an array'
do
let
(
:when
)
{
%w[unknown_failure runner_system_failure]
}
it
'returns when as it was passed'
do
expect
(
value
).
to
eq
(
when:
%w[unknown_failure runner_system_failure]
)
end
end
end
end
describe
'validation'
do
context
'when retry value is correct'
do
context
'when it is a numeric'
do
let
(
:
config
)
{
2
}
context
'when it is a numeric'
,
:numeric
do
let
(
:
max
)
{
2
}
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
context
'when it is a hash without when'
do
let
(
:config
)
{
{
max:
2
}
}
context
'when it is a hash'
,
:hash
do
context
'with max'
do
let
(
:max
)
{
2
}
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
context
'when it is a hash
with string when'
do
let
(
:config
)
{
{
max:
2
,
when:
'unknown_failure'
}
}
context
'
with string when'
do
let
(
:when
)
{
'unknown_failure'
}
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
context
'when it is a hash
with string when always'
do
let
(
:config
)
{
{
max:
2
,
when:
'always'
}
}
context
'
with string when always'
do
let
(
:when
)
{
'always'
}
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
context
'when it is a hash
with array when'
do
let
(
:config
)
{
{
max:
2
,
when:
%w[unknown_failure runner_system_failure]
}
}
context
'
with array when'
do
let
(
:when
)
{
%w[unknown_failure runner_system_failure]
}
it
'is valid'
do
expect
(
entry
).
to
be_valid
...
...
@@ -62,14 +104,25 @@ describe Gitlab::Ci::Config::Entry::Retry do
]
.
freeze
RETRY_WHEN_IN_DOCUMENTATION
.
each
do
|
reason
|
context
"when it is a hash with value
from documentation `
#{
reason
}
`"
do
let
(
:config
)
{
{
max:
2
,
when:
reason
}
}
context
"with when
from documentation `
#{
reason
}
`"
do
let
(
:when
)
{
reason
}
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
end
CommitStatus
.
failure_reasons
.
each_key
do
|
reason
|
context
"with when from CommitStatus.failure_reasons `
#{
reason
}
`"
do
let
(
:when
)
{
reason
}
it
'is valid'
do
expect
(
entry
).
to
be_valid
end
end
end
end
end
context
'when retry value is not correct'
do
...
...
@@ -82,9 +135,9 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'
not defined as a hash'
do
context
'
when it is a numeric'
,
:numeric
do
context
'when it is lower than zero'
do
let
(
:
config
)
{
-
1
}
let
(
:
max
)
{
-
1
}
it
'returns error about value too low'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -94,7 +147,7 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
context
'when it is not an integer'
do
let
(
:
config
)
{
1.5
}
let
(
:
max
)
{
1.5
}
it
'returns error about wrong value'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -103,7 +156,7 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
context
'when the value is too high'
do
let
(
:
config
)
{
10
}
let
(
:
max
)
{
10
}
it
'returns error about value too high'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -112,7 +165,7 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'
defined as a hash'
do
context
'
when it is a hash'
,
:hash
do
context
'with unknown keys'
do
let
(
:config
)
{
{
max:
2
,
unknown_key: :something
,
one_more: :key
}
}
...
...
@@ -123,8 +176,8 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'w
hen max is
lower than zero'
do
let
(
:
config
)
{
{
max:
-
1
}
}
context
'w
ith max
lower than zero'
do
let
(
:
max
)
{
-
1
}
it
'returns error about value too low'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -133,8 +186,8 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'w
hen max is
not an integer'
do
let
(
:
config
)
{
{
max:
1.5
}
}
context
'w
ith max
not an integer'
do
let
(
:
max
)
{
1.5
}
it
'returns error about wrong value'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -142,8 +195,8 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'
when max is
too high'
do
let
(
:
config
)
{
{
max:
10
}
}
context
'
iwth max
too high'
do
let
(
:
max
)
{
10
}
it
'returns error about value too high'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -151,8 +204,8 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'w
hen when has the
wrong format'
do
let
(
:
config
)
{
{
when:
true
}
}
context
'w
ith when in
wrong format'
do
let
(
:
when
)
{
true
}
it
'returns error about the wrong format'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -160,8 +213,8 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'w
hen when is a string and unknown
'
do
let
(
:
config
)
{
{
when:
'unknown_reason'
}
}
context
'w
ith an unknown when string
'
do
let
(
:
when
)
{
'unknown_reason'
}
it
'returns error about the wrong format'
do
expect
(
entry
).
not_to
be_valid
...
...
@@ -169,8 +222,8 @@ describe Gitlab::Ci::Config::Entry::Retry do
end
end
context
'w
hen when is an array and includes unknown failures
'
do
let
(
:
config
)
{
{
when:
%w[unknown_reason runner_system_failure]
}
}
context
'w
ith an unknown failure reason in a when array
'
do
let
(
:
when
)
{
%w[unknown_reason runner_system_failure]
}
it
'returns error about the wrong format'
do
expect
(
entry
).
not_to
be_valid
...
...
spec/models/ci/build_spec.rb
View file @
9818bb56
...
...
@@ -1472,15 +1472,7 @@ describe Ci::Build do
end
describe
'#retries_max'
do
context
'when max retries value is defined as an integer'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
1
})
}
it
'returns the number of configured max retries'
do
expect
(
subject
.
retries_max
).
to
eq
1
end
end
context
'when retries value is defined as a hash'
do
context
'with retries max config option'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
{
max:
1
}
})
}
it
'returns the number of configured max retries'
do
...
...
@@ -1488,15 +1480,7 @@ describe Ci::Build do
end
end
context
'when retries value is defined as a hash without max key'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
{
something: :else
}
})
}
it
'returns zero'
do
expect
(
subject
.
retries_max
).
to
eq
0
end
end
context
'when max retries value is not defined'
do
context
'without retries max config option'
do
subject
{
create
(
:ci_build
)
}
it
'returns zero'
do
...
...
@@ -1514,34 +1498,18 @@ describe Ci::Build do
end
describe
'#retry_when'
do
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 as an array'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
{
when:
%w[something more]
}
})
}
context
'with retries when config option'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
{
when:
[
'some_reason'
]
}
})
}
it
'returns the configured
value
'
do
expect
(
subject
.
retry_when
).
to
eq
%w[something more
]
it
'returns the configured
when
'
do
expect
(
subject
.
retry_when
).
to
eq
[
'some_reason'
]
end
end
context
'w
hen value is not defined
'
do
context
'w
ithout retries when config option
'
do
subject
{
create
(
:ci_build
)
}
it
'returns `always`'
do
expect
(
subject
.
retry_when
).
to
eq
[
'always'
]
end
end
context
'when retry is only defined as an integer'
do
subject
{
create
(
:ci_build
,
options:
{
retry:
1
})
}
it
'returns `always`'
do
it
'returns always array'
do
expect
(
subject
.
retry_when
).
to
eq
[
'always'
]
end
end
...
...
@@ -3001,7 +2969,7 @@ describe Ci::Build do
end
context
'when build is configured to be retried'
do
subject
{
create
(
:ci_build
,
:running
,
options:
{
retry:
3
},
project:
project
,
user:
user
)
}
subject
{
create
(
:ci_build
,
:running
,
options:
{
retry:
{
max:
3
}
},
project:
project
,
user:
user
)
}
it
'retries build and assigns the same user to it'
do
expect
(
described_class
).
to
receive
(
:retry
)
...
...
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