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
4f7f3258
Commit
4f7f3258
authored
Jun 01, 2016
by
Lin Jen-Shin
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Implement the logic for locking runner
parent
86076012
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
72 additions
and
5 deletions
+72
-5
app/models/ci/build.rb
app/models/ci/build.rb
+1
-3
app/models/ci/runner.rb
app/models/ci/runner.rb
+18
-0
spec/models/build_spec.rb
spec/models/build_spec.rb
+53
-2
No files found.
app/models/ci/build.rb
View file @
4f7f3258
...
...
@@ -291,9 +291,7 @@ module Ci
end
def
can_be_served?
(
runner
)
return
false
unless
has_tags?
||
runner
.
run_untagged?
(
tag_list
-
runner
.
tag_list
).
empty?
runner
.
can_serve?
(
self
)
end
def
has_tags?
...
...
app/models/ci/runner.rb
View file @
4f7f3258
...
...
@@ -91,6 +91,12 @@ module Ci
!
shared?
end
def
can_serve?
(
build
)
not_locked_or_locked_to?
(
build
.
project
)
&&
run_untagged_or_has_tags?
(
build
)
&&
accepting_tags?
(
build
.
tag_list
)
end
def
only_for?
(
project
)
projects
==
[
project
]
end
...
...
@@ -111,5 +117,17 @@ module Ci
'can not be empty when runner is not allowed to pick untagged jobs'
)
end
end
def
not_locked_or_locked_to?
(
project
)
!
locked?
||
projects
.
exists?
(
id:
project
.
id
)
end
def
run_untagged_or_has_tags?
(
build
)
run_untagged?
||
build
.
has_tags?
end
def
accepting_tags?
(
target_tags
)
(
target_tags
-
tag_list
).
empty?
end
end
end
spec/models/build_spec.rb
View file @
4f7f3258
...
...
@@ -296,16 +296,67 @@ describe Ci::Build, models: true do
it_behaves_like
'tagged build picker'
end
context
'when runner can
not pick untagged jobs'
do
context
'when runner cannot pick untagged jobs'
do
before
{
runner
.
run_untagged
=
false
}
it
'can
not handle builds without tags'
do
it
'cannot handle builds without tags'
do
expect
(
build
.
can_be_served?
(
runner
)).
to
be_falsey
end
it_behaves_like
'tagged build picker'
end
end
context
'when runner is locked'
do
before
{
runner
.
locked
=
true
}
shared_examples
'locked build picker'
do
|
serve_matching_tags
|
context
'when runner cannot pick untagged jobs'
do
before
{
runner
.
run_untagged
=
false
}
it
'cannot handle builds without tags'
do
expect
(
build
.
can_be_served?
(
runner
)).
to
be_falsey
end
end
context
'when having runner tags'
do
before
{
runner
.
tag_list
=
[
'bb'
,
'cc'
]
}
it
"
#{
serve_matching_tags
}
handle it for matching tags"
do
build
.
tag_list
=
[
'bb'
]
expected
=
if
serve_matching_tags
be_truthy
else
be_falsey
end
expect
(
build
.
can_be_served?
(
runner
)).
to
expected
end
it
'cannot handle it for builds without matching tags'
do
build
.
tag_list
=
[
'aa'
]
expect
(
build
.
can_be_served?
(
runner
)).
to
be_falsey
end
end
end
context
'when serving the same project'
do
it
'can handle it'
do
expect
(
build
.
can_be_served?
(
runner
)).
to
be_truthy
end
it_behaves_like
'locked build picker'
,
true
end
context
'serving a different project'
do
before
{
runner
.
runner_projects
.
destroy_all
}
it
'cannot handle it'
do
expect
(
build
.
can_be_served?
(
runner
)).
to
be_falsey
end
it_behaves_like
'locked build picker'
,
false
end
end
end
describe
'#has_tags?'
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