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
7008ed1e
Commit
7008ed1e
authored
Mar 26, 2018
by
Tomasz Maczukin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Change and rename behavior of save_timeout_state!
parent
c2bc1533
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
33 additions
and
10 deletions
+33
-10
app/models/ci/build.rb
app/models/ci/build.rb
+1
-1
app/models/ci/build_metadata.rb
app/models/ci/build_metadata.rb
+2
-2
spec/models/ci/build_metadata_spec.rb
spec/models/ci/build_metadata_spec.rb
+7
-7
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+23
-0
No files found.
app/models/ci/build.rb
View file @
7008ed1e
...
@@ -157,7 +157,7 @@ module Ci
...
@@ -157,7 +157,7 @@ module Ci
end
end
before_transition
pending: :running
do
|
build
|
before_transition
pending: :running
do
|
build
|
build
.
ensure_metadata
.
save_timeout_state!
build
.
ensure_metadata
.
update_timeout_state
end
end
end
end
...
...
app/models/ci/build_metadata.rb
View file @
7008ed1e
...
@@ -21,14 +21,14 @@ module Ci
...
@@ -21,14 +21,14 @@ module Ci
runner_timeout_source:
3
runner_timeout_source:
3
}
}
def
save_timeout_state!
def
update_timeout_state
return
unless
build
.
runner
.
present?
return
unless
build
.
runner
.
present?
project_timeout
=
project
&
.
build_timeout
project_timeout
=
project
&
.
build_timeout
timeout
=
[
project_timeout
,
build
.
runner
.
maximum_timeout
].
compact
.
min
timeout
=
[
project_timeout
,
build
.
runner
.
maximum_timeout
].
compact
.
min
timeout_source
=
timeout
<
project_timeout
?
:runner_timeout_source
:
:project_timeout_source
timeout_source
=
timeout
<
project_timeout
?
:runner_timeout_source
:
:project_timeout_source
update
!
(
timeout:
timeout
,
timeout_source:
timeout_source
)
update
(
timeout:
timeout
,
timeout_source:
timeout_source
)
end
end
end
end
end
end
spec/models/ci/build_metadata_spec.rb
View file @
7008ed1e
...
@@ -15,16 +15,16 @@ describe Ci::BuildMetadata do
...
@@ -15,16 +15,16 @@ describe Ci::BuildMetadata do
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let
(
:build_metadata
)
{
create
(
:ci_build_metadata
,
build:
build
)
}
let
(
:build_metadata
)
{
create
(
:ci_build_metadata
,
build:
build
)
}
describe
'#
save_timeout_state!
'
do
describe
'#
update_timeout_state
'
do
subject
{
build_metadata
}
subject
{
build_metadata
}
context
'when runner is not assigned to the job'
do
context
'when runner is not assigned to the job'
do
it
"doesn't change timeout value"
do
it
"doesn't change timeout value"
do
expect
{
subject
.
save_timeout_state!
}.
not_to
change
{
subject
.
reload
.
timeout
}
expect
{
subject
.
update_timeout_state
}.
not_to
change
{
subject
.
reload
.
timeout
}
end
end
it
"doesn't change timeout_source value"
do
it
"doesn't change timeout_source value"
do
expect
{
subject
.
save_timeout_state!
}.
not_to
change
{
subject
.
reload
.
timeout_source
}
expect
{
subject
.
update_timeout_state
}.
not_to
change
{
subject
.
reload
.
timeout_source
}
end
end
end
end
...
@@ -37,11 +37,11 @@ describe Ci::BuildMetadata do
...
@@ -37,11 +37,11 @@ describe Ci::BuildMetadata do
let
(
:runner
)
{
create
(
:ci_runner
,
maximum_timeout:
1900
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
maximum_timeout:
1900
)
}
it
'sets runner timeout'
do
it
'sets runner timeout'
do
expect
{
subject
.
save_timeout_state!
}.
to
change
{
subject
.
reload
.
timeout
}.
to
(
1900
)
expect
{
subject
.
update_timeout_state
}.
to
change
{
subject
.
reload
.
timeout
}.
to
(
1900
)
end
end
it
'sets runner_timeout_source'
do
it
'sets runner_timeout_source'
do
expect
{
subject
.
save_timeout_state!
}.
to
change
{
subject
.
reload
.
timeout_source
}.
to
(
'runner_timeout_source'
)
expect
{
subject
.
update_timeout_state
}.
to
change
{
subject
.
reload
.
timeout_source
}.
to
(
'runner_timeout_source'
)
end
end
end
end
...
@@ -49,11 +49,11 @@ describe Ci::BuildMetadata do
...
@@ -49,11 +49,11 @@ describe Ci::BuildMetadata do
let
(
:runner
)
{
create
(
:ci_runner
,
maximum_timeout:
2100
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
maximum_timeout:
2100
)
}
it
'sets project timeout'
do
it
'sets project timeout'
do
expect
{
subject
.
save_timeout_state!
}.
to
change
{
subject
.
reload
.
timeout
}.
to
(
2000
)
expect
{
subject
.
update_timeout_state
}.
to
change
{
subject
.
reload
.
timeout
}.
to
(
2000
)
end
end
it
'sets project_timeout_source'
do
it
'sets project_timeout_source'
do
expect
{
subject
.
save_timeout_state!
}.
to
change
{
subject
.
reload
.
timeout_source
}.
to
(
'project_timeout_source'
)
expect
{
subject
.
update_timeout_state
}.
to
change
{
subject
.
reload
.
timeout_source
}.
to
(
'project_timeout_source'
)
end
end
end
end
end
end
...
...
spec/models/ci/build_spec.rb
View file @
7008ed1e
...
@@ -2050,6 +2050,11 @@ describe Ci::Build do
...
@@ -2050,6 +2050,11 @@ describe Ci::Build do
job
.
project
.
update_attribute
(
:build_timeout
,
1800
)
job
.
project
.
update_attribute
(
:build_timeout
,
1800
)
end
end
def
run_job_without_exception
job
.
run!
rescue
StateMachines
::
InvalidTransition
end
shared_examples
'saves data on transition'
do
shared_examples
'saves data on transition'
do
it
'saves timeout'
do
it
'saves timeout'
do
expect
{
job
.
run!
}.
to
change
{
job
.
reload
.
ensure_metadata
.
timeout
}.
from
(
nil
).
to
(
expected_timeout
)
expect
{
job
.
run!
}.
to
change
{
job
.
reload
.
ensure_metadata
.
timeout
}.
from
(
nil
).
to
(
expected_timeout
)
...
@@ -2058,6 +2063,24 @@ describe Ci::Build do
...
@@ -2058,6 +2063,24 @@ describe Ci::Build do
it
'saves timeout_source'
do
it
'saves timeout_source'
do
expect
{
job
.
run!
}.
to
change
{
job
.
reload
.
ensure_metadata
.
timeout_source
}.
from
(
'unknown_timeout_source'
).
to
(
expected_timeout_source
)
expect
{
job
.
run!
}.
to
change
{
job
.
reload
.
ensure_metadata
.
timeout_source
}.
from
(
'unknown_timeout_source'
).
to
(
expected_timeout_source
)
end
end
context
'when Ci::BuildMetadata#update_timeout_state fails update'
do
before
do
allow_any_instance_of
(
Ci
::
BuildMetadata
).
to
receive
(
:update_timeout_state
).
and_return
(
false
)
end
it
"doesn't save timeout"
do
expect
{
run_job_without_exception
}.
not_to
change
{
job
.
reload
.
ensure_metadata
.
timeout_source
}
end
it
"doesn't save timeout_source"
do
expect
{
run_job_without_exception
}.
not_to
change
{
job
.
reload
.
ensure_metadata
.
timeout_source
}
end
it
'raises an exception'
do
expect
{
job
.
run!
}.
to
raise_error
(
StateMachines
::
InvalidTransition
)
end
end
end
end
context
'when runner timeout overrides project timeout'
do
context
'when runner timeout overrides project timeout'
do
...
...
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