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
834f4738
Commit
834f4738
authored
Feb 19, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Override project-defined timeout with runner-defined one
parent
7b82f4ba
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
87 additions
and
1 deletion
+87
-1
app/models/ci/build.rb
app/models/ci/build.rb
+7
-0
app/models/ci/runner.rb
app/models/ci/runner.rb
+4
-0
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+23
-1
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+18
-0
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+35
-0
No files found.
app/models/ci/build.rb
View file @
834f4738
...
...
@@ -232,9 +232,16 @@ module Ci
end
def
timeout
return
runner
.
job_upper_timeout
if
should_use_runner_timeout
project
.
build_timeout
end
def
should_use_runner_timeout
runner
&&
runner
.
defines_job_upper_timeout?
&&
runner
.
job_upper_timeout
<
project
.
build_timeout
end
private
:should_use_runner_timeout
def
triggered_by?
(
current_user
)
user
==
current_user
end
...
...
app/models/ci/runner.rb
View file @
834f4738
...
...
@@ -167,6 +167,10 @@ module Ci
end
end
def
defines_job_upper_timeout?
job_upper_timeout
&&
job_upper_timeout
>
0
end
private
def
cleanup_runner_queue
...
...
spec/models/ci/build_spec.rb
View file @
834f4738
...
...
@@ -1272,8 +1272,30 @@ describe Ci::Build do
describe
'project settings'
do
describe
'#timeout'
do
set
(
:project2
)
{
create
(
:project
,
:repository
,
group:
group
,
build_timeout:
1000
)
}
set
(
:pipeline2
)
{
create
(
:ci_pipeline
,
project:
project2
,
sha:
project2
.
commit
.
id
,
ref:
project2
.
default_branch
,
status:
'success'
)
}
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline2
)
}
it
'returns project timeout configuration'
do
expect
(
build
.
timeout
).
to
eq
(
project2
.
build_timeout
)
end
context
'when runner sets timeout to bigger value'
do
let
(
:runner2
)
{
create
(
:ci_runner
,
job_upper_timeout:
2000
)
}
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline2
,
runner:
runner2
)
}
it
'returns project timeout configuration'
do
expect
(
build
.
timeout
).
to
eq
(
project
.
build_timeout
)
expect
(
build
.
timeout
).
to
eq
(
project2
.
build_timeout
)
end
end
context
'when runner sets timeout to smaller value'
do
let
(
:runner2
)
{
create
(
:ci_runner
,
job_upper_timeout:
500
)
}
let
(
:build
)
{
create
(
:ci_build
,
:manual
,
pipeline:
pipeline2
,
runner:
runner2
)
}
it
'returns project timeout configuration'
do
expect
(
build
.
timeout
).
to
eq
(
runner2
.
job_upper_timeout
)
end
end
end
...
...
spec/models/ci/runner_spec.rb
View file @
834f4738
...
...
@@ -556,6 +556,24 @@ describe Ci::Runner do
end
end
describe
'#defines_job_upper_timeout?'
do
context
'when job upper timeout is specified'
do
subject
{
create
(
:ci_runner
,
job_upper_timeout:
1234
)
}
it
'should return true'
do
expect
(
subject
.
defines_job_upper_timeout?
).
to
be_truthy
end
end
context
'when job upper timeout is not specified'
do
subject
{
create
(
:ci_runner
)
}
it
'should return false'
do
expect
(
subject
.
defines_job_upper_timeout?
).
to
be_falsey
end
end
end
describe
'.search'
do
let
(
:runner
)
{
create
(
:ci_runner
,
token:
'123abc'
,
description:
'test runner'
)
}
...
...
spec/requests/api/runner_spec.rb
View file @
834f4738
...
...
@@ -658,6 +658,41 @@ describe API::Runner do
end
end
end
describe
'timeout support'
do
context
'when project specifies job timeout'
do
let
(
:project
)
{
create
(
:project
,
shared_runners_enabled:
false
,
build_timeout:
1234
)
}
it
'contains info about timeout taken from project'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'runner_info'
]).
to
include
({
'timeout'
=>
1234
})
end
context
'when runner specifies lower timeout'
do
let
(
:runner
)
{
create
(
:ci_runner
,
job_upper_timeout:
1000
)
}
it
'contains info about timeout overridden by runner'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'runner_info'
]).
to
include
({
'timeout'
=>
1000
})
end
end
context
'when runner specifies bigger timeout'
do
let
(
:runner
)
{
create
(
:ci_runner
,
job_upper_timeout:
2000
)
}
it
'contains info about timeout not overridden by runner'
do
request_job
expect
(
response
).
to
have_gitlab_http_status
(
201
)
expect
(
json_response
[
'runner_info'
]).
to
include
({
'timeout'
=>
1234
})
end
end
end
end
end
def
request_job
(
token
=
runner
.
token
,
**
params
)
...
...
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