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
Léo-Paul Géneau
gitlab-ce
Commits
051f385e
Commit
051f385e
authored
May 23, 2018
by
Kamil Trzciński
Committed by
Dylan Griffith
May 31, 2018
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Refactor validations and make runner factory by default to be instance-wide runner
parent
5c34c3fc
Changes
19
Show whitespace changes
Inline
Side-by-side
Showing
19 changed files
with
134 additions
and
140 deletions
+134
-140
app/models/ci/runner.rb
app/models/ci/runner.rb
+25
-10
spec/controllers/groups/runners_controller_spec.rb
spec/controllers/groups/runners_controller_spec.rb
+1
-2
spec/controllers/projects/runners_controller_spec.rb
spec/controllers/projects/runners_controller_spec.rb
+1
-2
spec/controllers/projects/settings/ci_cd_controller_spec.rb
spec/controllers/projects/settings/ci_cd_controller_spec.rb
+4
-4
spec/factories/ci/runner_projects.rb
spec/factories/ci/runner_projects.rb
+1
-1
spec/factories/ci/runners.rb
spec/factories/ci/runners.rb
+5
-15
spec/features/admin/admin_runners_spec.rb
spec/features/admin/admin_runners_spec.rb
+10
-7
spec/features/runners_spec.rb
spec/features/runners_spec.rb
+2
-7
spec/finders/runner_jobs_finder_spec.rb
spec/finders/runner_jobs_finder_spec.rb
+1
-1
spec/models/ci/build_spec.rb
spec/models/ci/build_spec.rb
+2
-8
spec/models/ci/pipeline_spec.rb
spec/models/ci/pipeline_spec.rb
+1
-1
spec/models/ci/runner_spec.rb
spec/models/ci/runner_spec.rb
+68
-60
spec/models/project_spec.rb
spec/models/project_spec.rb
+5
-5
spec/models/user_spec.rb
spec/models/user_spec.rb
+1
-2
spec/requests/api/runner_spec.rb
spec/requests/api/runner_spec.rb
+2
-6
spec/requests/api/runners_spec.rb
spec/requests/api/runners_spec.rb
+1
-1
spec/serializers/runner_entity_spec.rb
spec/serializers/runner_entity_spec.rb
+2
-2
spec/services/ci/register_job_service_spec.rb
spec/services/ci/register_job_service_spec.rb
+1
-1
spec/services/ci/update_build_queue_service_spec.rb
spec/services/ci/update_build_queue_service_spec.rb
+1
-5
No files found.
app/models/ci/runner.rb
View file @
051f385e
...
@@ -56,12 +56,15 @@ module Ci
...
@@ -56,12 +56,15 @@ module Ci
end
end
validate
:tag_constraints
validate
:tag_constraints
validate
:no_projects
,
unless: :project_type?
validate
:no_groups
,
unless: :group_type?
validate
:only_one_group
,
if: :group_type?
validates
:access_level
,
presence:
true
validates
:access_level
,
presence:
true
validates
:runner_type
,
presence:
true
validates
:runner_type
,
presence:
true
validate
:no_projects
,
unless: :project_type?
validate
:no_groups
,
unless: :group_type?
validate
:any_project
,
if: :project_type?
validate
:exactly_one_group
,
if: :group_type?
validate
:is_shared_is_valid
acts_as_taggable
acts_as_taggable
after_destroy
:cleanup_runner_queue
after_destroy
:cleanup_runner_queue
...
@@ -117,8 +120,8 @@ module Ci
...
@@ -117,8 +120,8 @@ module Ci
raise
ArgumentError
,
'Transitioning a group runner to a project runner is not supported'
raise
ArgumentError
,
'Transitioning a group runner to a project runner is not supported'
end
end
self
.
save
self
.
projects
<<
project
project
.
runner_projects
.
create
(
runner_id:
self
.
id
)
self
.
save!
end
end
def
display_name
def
display_name
...
@@ -257,19 +260,31 @@ module Ci
...
@@ -257,19 +260,31 @@ module Ci
def
no_projects
def
no_projects
if
projects
.
any?
if
projects
.
any?
errors
.
add
(
:runner
,
'cannot
assign project to a non-project runner
'
)
errors
.
add
(
:runner
,
'cannot
have projects assigned
'
)
end
end
end
end
def
no_groups
def
no_groups
if
groups
.
any?
if
groups
.
any?
errors
.
add
(
:runner
,
'cannot assign group to a non-group runner'
)
errors
.
add
(
:runner
,
'cannot have groups assigned'
)
end
end
def
any_project
unless
projects
.
any?
errors
.
add
(
:runner
,
'needs to be assigned to at least one project'
)
end
end
def
exactly_one_group
unless
groups
.
one?
errors
.
add
(
:runner
,
'needs to be assigned to exactly one group'
)
end
end
end
end
def
only_one_group
def
is_shared_is_valid
if
groups
.
many
?
unless
is_shared?
==
instance_type
?
errors
.
add
(
:
runner
,
'can only be assigned to one group
'
)
errors
.
add
(
:
is_shared
,
'is not equal to instance_type?
'
)
end
end
end
end
...
...
spec/controllers/groups/runners_controller_spec.rb
View file @
051f385e
...
@@ -3,7 +3,7 @@ require 'spec_helper'
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Groups
::
RunnersController
do
describe
Groups
::
RunnersController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:group
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
]
)
}
let
(
:params
)
do
let
(
:params
)
do
{
{
...
@@ -15,7 +15,6 @@ describe Groups::RunnersController do
...
@@ -15,7 +15,6 @@ describe Groups::RunnersController do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
group
.
add_master
(
user
)
group
.
add_master
(
user
)
group
.
runners
<<
runner
end
end
describe
'#update'
do
describe
'#update'
do
...
...
spec/controllers/projects/runners_controller_spec.rb
View file @
051f385e
...
@@ -3,7 +3,7 @@ require 'spec_helper'
...
@@ -3,7 +3,7 @@ require 'spec_helper'
describe
Projects
::
RunnersController
do
describe
Projects
::
RunnersController
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:runner
)
{
create
(
:ci_runner
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
]
)
}
let
(
:params
)
do
let
(
:params
)
do
{
{
...
@@ -16,7 +16,6 @@ describe Projects::RunnersController do
...
@@ -16,7 +16,6 @@ describe Projects::RunnersController do
before
do
before
do
sign_in
(
user
)
sign_in
(
user
)
project
.
add_master
(
user
)
project
.
add_master
(
user
)
project
.
runners
<<
runner
end
end
describe
'#update'
do
describe
'#update'
do
...
...
spec/controllers/projects/settings/ci_cd_controller_spec.rb
View file @
051f385e
...
@@ -19,12 +19,12 @@ describe Projects::Settings::CiCdController do
...
@@ -19,12 +19,12 @@ describe Projects::Settings::CiCdController do
end
end
context
'with group runners'
do
context
'with group runners'
do
let
(
:group_runner
)
{
create
(
:ci_runner
,
runner_type: :group_type
)
}
let
(
:parent_group
)
{
create
(
:group
)
}
let
(
:parent_group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
,
runners:
[
group_runner
],
parent:
parent_group
)
}
let
(
:group
)
{
create
(
:group
,
parent:
parent_group
)
}
let
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
let
(
:other_project
)
{
create
(
:project
,
group:
group
)
}
let
(
:other_project
)
{
create
(
:project
,
group:
group
)
}
let!
(
:project_runner
)
{
create
(
:ci_runner
,
projects:
[
other_project
],
runner_type: :project_type
)
}
let!
(
:project_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
other_project
]
)
}
let!
(
:shared_runner
)
{
create
(
:ci_runner
,
:
shared
)
}
let!
(
:shared_runner
)
{
create
(
:ci_runner
,
:
instance
)
}
it
'sets assignable project runners only'
do
it
'sets assignable project runners only'
do
group
.
add_master
(
user
)
group
.
add_master
(
user
)
...
...
spec/factories/ci/runner_projects.rb
View file @
051f385e
FactoryBot
.
define
do
FactoryBot
.
define
do
factory
:ci_runner_project
,
class:
Ci
::
RunnerProject
do
factory
:ci_runner_project
,
class:
Ci
::
RunnerProject
do
runner
factory:
:ci_runner
runner
factory:
[
:ci_runner
,
:project
]
project
project
end
end
end
end
spec/factories/ci/runners.rb
View file @
051f385e
...
@@ -3,37 +3,27 @@ FactoryBot.define do
...
@@ -3,37 +3,27 @@ FactoryBot.define do
sequence
(
:description
)
{
|
n
|
"My runner
#{
n
}
"
}
sequence
(
:description
)
{
|
n
|
"My runner
#{
n
}
"
}
platform
"darwin"
platform
"darwin"
is_shared
false
active
true
active
true
access_level
:not_protected
access_level
:not_protected
runner_type
:project_type
trait
:online
do
contacted_at
Time
.
now
end
trait
:shared
do
is_shared
true
is_shared
true
runner_type
:instance_type
runner_type
:instance_type
end
trait
:specific
do
trait
:instance
do
is_shared
false
is_shared
true
runner_type
:instance_type
end
end
trait
:group
do
trait
:group
do
is_shared
false
runner_type
:group_type
runner_type
:group_type
end
end
trait
:project
do
trait
:project
do
is_shared
false
runner_type
:project_type
runner_type
:project_type
end
end
trait
:instance
do
is_shared
true
runner_type
:instance_type
end
trait
:inactive
do
trait
:inactive
do
active
false
active
false
end
end
...
...
spec/features/admin/admin_runners_spec.rb
View file @
051f385e
...
@@ -76,7 +76,7 @@ describe "Admin Runners" do
...
@@ -76,7 +76,7 @@ describe "Admin Runners" do
context
'shared runner'
do
context
'shared runner'
do
it
'shows the label and does not show the project count'
do
it
'shows the label and does not show the project count'
do
runner
=
create
:ci_runner
,
:
shared
runner
=
create
:ci_runner
,
:
instance
visit
admin_runners_path
visit
admin_runners_path
...
@@ -90,7 +90,7 @@ describe "Admin Runners" do
...
@@ -90,7 +90,7 @@ describe "Admin Runners" do
context
'specific runner'
do
context
'specific runner'
do
it
'shows the label and the project count'
do
it
'shows the label and the project count'
do
project
=
create
:project
project
=
create
:project
runner
=
create
:ci_runner
,
projects:
[
project
]
runner
=
create
:ci_runner
,
:project
,
projects:
[
project
]
visit
admin_runners_path
visit
admin_runners_path
...
@@ -149,8 +149,9 @@ describe "Admin Runners" do
...
@@ -149,8 +149,9 @@ describe "Admin Runners" do
end
end
context
'with specific runner'
do
context
'with specific runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
@project1
])
}
before
do
before
do
@project1
.
runners
<<
runner
visit
admin_runner_path
(
runner
)
visit
admin_runner_path
(
runner
)
end
end
...
@@ -158,9 +159,9 @@ describe "Admin Runners" do
...
@@ -158,9 +159,9 @@ describe "Admin Runners" do
end
end
context
'with locked runner'
do
context
'with locked runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
@project1
],
locked:
true
)
}
before
do
before
do
runner
.
update
(
locked:
true
)
@project1
.
runners
<<
runner
visit
admin_runner_path
(
runner
)
visit
admin_runner_path
(
runner
)
end
end
...
@@ -168,9 +169,10 @@ describe "Admin Runners" do
...
@@ -168,9 +169,10 @@ describe "Admin Runners" do
end
end
context
'with shared runner'
do
context
'with shared runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
before
do
before
do
@project1
.
destroy
@project1
.
destroy
runner
.
update
(
is_shared:
true
)
visit
admin_runner_path
(
runner
)
visit
admin_runner_path
(
runner
)
end
end
...
@@ -179,8 +181,9 @@ describe "Admin Runners" do
...
@@ -179,8 +181,9 @@ describe "Admin Runners" do
end
end
describe
'disable/destroy'
do
describe
'disable/destroy'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
@project1
])
}
before
do
before
do
@project1
.
runners
<<
runner
visit
admin_runner_path
(
runner
)
visit
admin_runner_path
(
runner
)
end
end
...
...
spec/features/runners_spec.rb
View file @
051f385e
...
@@ -29,11 +29,7 @@ feature 'Runners' do
...
@@ -29,11 +29,7 @@ feature 'Runners' do
end
end
context
'when a project_type runner is activated on the project'
do
context
'when a project_type runner is activated on the project'
do
given
(
:specific_runner
)
{
create
(
:ci_runner
,
:project
)
}
given
(
:specific_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
specific_runner
])
}
background
do
project
.
runners
<<
specific_runner
end
scenario
'user sees the specific runner'
do
scenario
'user sees the specific runner'
do
visit
project_runners_path
(
project
)
visit
project_runners_path
(
project
)
...
@@ -126,11 +122,10 @@ feature 'Runners' do
...
@@ -126,11 +122,10 @@ feature 'Runners' do
context
'when a specific runner exists in another project'
do
context
'when a specific runner exists in another project'
do
given
(
:another_project
)
{
create
(
:project
)
}
given
(
:another_project
)
{
create
(
:project
)
}
given
(
:specific_runner
)
{
create
(
:ci_runner
,
:project
)
}
given
(
:specific_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
another_project
]
)
}
background
do
background
do
another_project
.
add_master
(
user
)
another_project
.
add_master
(
user
)
another_project
.
runners
<<
specific_runner
end
end
scenario
'user enables and disables a specific runner'
do
scenario
'user enables and disables a specific runner'
do
...
...
spec/finders/runner_jobs_finder_spec.rb
View file @
051f385e
...
@@ -2,7 +2,7 @@ require 'spec_helper'
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
RunnerJobsFinder
do
describe
RunnerJobsFinder
do
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:
shared
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:
instance
)
}
subject
{
described_class
.
new
(
runner
,
params
).
execute
}
subject
{
described_class
.
new
(
runner
,
params
).
execute
}
...
...
spec/models/ci/build_spec.rb
View file @
051f385e
...
@@ -148,10 +148,9 @@ describe Ci::Build do
...
@@ -148,10 +148,9 @@ describe Ci::Build do
end
end
context
'when there are runners'
do
context
'when there are runners'
do
let
(
:runner
)
{
create
(
:ci_runner
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
build
.
project
]
)
}
before
do
before
do
build
.
project
.
runners
<<
runner
runner
.
update_attributes
(
contacted_at:
1
.
second
.
ago
)
runner
.
update_attributes
(
contacted_at:
1
.
second
.
ago
)
end
end
...
@@ -1388,12 +1387,7 @@ describe Ci::Build do
...
@@ -1388,12 +1387,7 @@ describe Ci::Build do
it
{
is_expected
.
to
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
context
"and there are specific runner"
do
context
"and there are specific runner"
do
let
(
:runner
)
{
create
(
:ci_runner
,
contacted_at:
1
.
second
.
ago
)
}
let!
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
build
.
project
],
contacted_at:
1
.
second
.
ago
)
}
before
do
build
.
project
.
runners
<<
runner
runner
.
save
end
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
...
...
spec/models/ci/pipeline_spec.rb
View file @
051f385e
...
@@ -1589,7 +1589,7 @@ describe Ci::Pipeline, :mailer do
...
@@ -1589,7 +1589,7 @@ describe Ci::Pipeline, :mailer do
context
'when pipeline is not stuck'
do
context
'when pipeline is not stuck'
do
before
do
before
do
create
(
:ci_runner
,
:
shared
,
:online
)
create
(
:ci_runner
,
:
instance
,
:online
)
end
end
it
'is not stuck'
do
it
'is not stuck'
do
...
...
spec/models/ci/runner_spec.rb
View file @
051f385e
...
@@ -21,7 +21,7 @@ describe Ci::Runner do
...
@@ -21,7 +21,7 @@ describe Ci::Runner do
end
end
end
end
context
'#
on
ly_one_group'
do
context
'#
exact
ly_one_group'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
let
(
:runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
...
@@ -29,42 +29,43 @@ describe Ci::Runner do
...
@@ -29,42 +29,43 @@ describe Ci::Runner do
runner
.
groups
<<
build
(
:group
)
runner
.
groups
<<
build
(
:group
)
expect
(
runner
).
not_to
be_valid
expect
(
runner
).
not_to
be_valid
expect
(
runner
.
errors
.
full_messages
).
to
include
(
'Runner
can only be assigned to
one group'
)
expect
(
runner
.
errors
.
full_messages
).
to
include
(
'Runner
needs to be assigned to exactly
one group'
)
end
end
end
end
context
'runner_type validations'
do
context
'runner_type validations'
do
let
(
:group
)
{
create
(
:group
)
}
set
(
:group
)
{
create
(
:group
)
}
set
(
:project
)
{
create
(
:project
)
}
let
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
let
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
let
(
:project_runner
)
{
create
(
:ci_runner
,
:project
)
}
let
(
:project_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
]
)
}
let
(
:instance_runner
)
{
create
(
:ci_runner
,
:instance
)
}
let
(
:instance_runner
)
{
create
(
:ci_runner
,
:instance
)
}
it
'disallows assigning group to project_type runner'
do
it
'disallows assigning group to project_type runner'
do
project_runner
.
groups
<<
build
(
:group
)
project_runner
.
groups
<<
build
(
:group
)
expect
(
project_runner
).
not_to
be_valid
expect
(
project_runner
).
not_to
be_valid
expect
(
project_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
assign group to a non-group runner
'
)
expect
(
project_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
have groups assigned
'
)
end
end
it
'disallows assigning group to instance_type runner'
do
it
'disallows assigning group to instance_type runner'
do
instance_runner
.
groups
<<
build
(
:group
)
instance_runner
.
groups
<<
build
(
:group
)
expect
(
instance_runner
).
not_to
be_valid
expect
(
instance_runner
).
not_to
be_valid
expect
(
instance_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
assign group to a non-group runner
'
)
expect
(
instance_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
have groups assigned
'
)
end
end
it
'disallows assigning project to group_type runner'
do
it
'disallows assigning project to group_type runner'
do
group_runner
.
projects
<<
build
(
:project
)
group_runner
.
projects
<<
build
(
:project
)
expect
(
group_runner
).
not_to
be_valid
expect
(
group_runner
).
not_to
be_valid
expect
(
group_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
assign project to a non-project runner
'
)
expect
(
group_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
have projects assigned
'
)
end
end
it
'disallows assigning project to instance_type runner'
do
it
'disallows assigning project to instance_type runner'
do
instance_runner
.
projects
<<
build
(
:project
)
instance_runner
.
projects
<<
build
(
:project
)
expect
(
instance_runner
).
not_to
be_valid
expect
(
instance_runner
).
not_to
be_valid
expect
(
instance_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
assign project to a non-project runner
'
)
expect
(
instance_runner
.
errors
.
full_messages
).
to
include
(
'Runner cannot
have projects assigned
'
)
end
end
it
'should fail to save a group assigned to a project runner even if the runner is already saved'
do
it
'should fail to save a group assigned to a project runner even if the runner is already saved'
do
...
@@ -107,8 +108,8 @@ describe Ci::Runner do
...
@@ -107,8 +108,8 @@ describe Ci::Runner do
describe
'.shared'
do
describe
'.shared'
do
let
(
:group
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let!
(
:group_runner
)
{
create
(
:ci_runner
,
:group
)
}
let!
(
:group_runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
]
)
}
let!
(
:project_runner
)
{
create
(
:ci_runner
,
:project
)
}
let!
(
:project_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
]
)
}
let!
(
:shared_runner
)
{
create
(
:ci_runner
,
:instance
)
}
let!
(
:shared_runner
)
{
create
(
:ci_runner
,
:instance
)
}
it
'returns only shared runners'
do
it
'returns only shared runners'
do
...
@@ -120,11 +121,11 @@ describe Ci::Runner do
...
@@ -120,11 +121,11 @@ describe Ci::Runner do
it
'returns the specific project runner'
do
it
'returns the specific project runner'
do
# own
# own
specific_project
=
create
(
:project
)
specific_project
=
create
(
:project
)
specific_runner
=
create
(
:ci_runner
,
:
specific
,
projects:
[
specific_project
])
specific_runner
=
create
(
:ci_runner
,
:
project
,
projects:
[
specific_project
])
# other
# other
other_project
=
create
(
:project
)
other_project
=
create
(
:project
)
create
(
:ci_runner
,
:
specific
,
projects:
[
other_project
])
create
(
:ci_runner
,
:
project
,
projects:
[
other_project
])
expect
(
described_class
.
belonging_to_project
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
expect
(
described_class
.
belonging_to_project
(
specific_project
.
id
)).
to
eq
[
specific_runner
]
end
end
...
@@ -175,31 +176,32 @@ describe Ci::Runner do
...
@@ -175,31 +176,32 @@ describe Ci::Runner do
describe
'#display_name'
do
describe
'#display_name'
do
it
'returns the description if it has a value'
do
it
'returns the description if it has a value'
do
runner
=
FactoryBot
.
build
(
:ci_runner
,
description:
'Linux/Ruby-1.9.3-p448'
)
runner
=
build
(
:ci_runner
,
description:
'Linux/Ruby-1.9.3-p448'
)
expect
(
runner
.
display_name
).
to
eq
'Linux/Ruby-1.9.3-p448'
expect
(
runner
.
display_name
).
to
eq
'Linux/Ruby-1.9.3-p448'
end
end
it
'returns the token if it does not have a description'
do
it
'returns the token if it does not have a description'
do
runner
=
FactoryBot
.
create
(
:ci_runner
)
runner
=
create
(
:ci_runner
)
expect
(
runner
.
display_name
).
to
eq
runner
.
description
expect
(
runner
.
display_name
).
to
eq
runner
.
description
end
end
it
'returns the token if the description is an empty string'
do
it
'returns the token if the description is an empty string'
do
runner
=
FactoryBot
.
build
(
:ci_runner
,
description:
''
,
token:
'token'
)
runner
=
build
(
:ci_runner
,
description:
''
,
token:
'token'
)
expect
(
runner
.
display_name
).
to
eq
runner
.
token
expect
(
runner
.
display_name
).
to
eq
runner
.
token
end
end
end
end
describe
'#assign_to'
do
describe
'#assign_to'
do
let
!
(
:project
)
{
FactoryBot
.
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
subject
{
runner
.
assign_to
(
project
)
}
subject
{
runner
.
assign_to
(
project
)
}
context
'with shared_runner'
do
context
'with shared_runner'
do
let
!
(
:runner
)
{
FactoryBot
.
create
(
:ci_runner
,
:shared
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
it
'transitions shared runner to project runner and assigns project'
do
it
'transitions shared runner to project runner and assigns project'
do
subject
subject
expect
(
runner
).
to
be_specific
expect
(
runner
).
to
be_specific
expect
(
runner
).
to
be_project_type
expect
(
runner
).
to
be_project_type
expect
(
runner
.
projects
).
to
eq
([
project
])
expect
(
runner
.
projects
).
to
eq
([
project
])
...
@@ -208,7 +210,8 @@ describe Ci::Runner do
...
@@ -208,7 +210,8 @@ describe Ci::Runner do
end
end
context
'with group runner'
do
context
'with group runner'
do
let!
(
:runner
)
{
FactoryBot
.
create
(
:ci_runner
,
:group
)
}
let
(
:group
)
{
create
(
:group
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:group
,
groups:
[
group
])
}
it
'raises an error'
do
it
'raises an error'
do
expect
{
subject
}
expect
{
subject
}
...
@@ -221,15 +224,15 @@ describe Ci::Runner do
...
@@ -221,15 +224,15 @@ describe Ci::Runner do
subject
{
described_class
.
online
}
subject
{
described_class
.
online
}
before
do
before
do
@runner1
=
FactoryBot
.
create
(
:ci_runner
,
:shared
,
contacted_at:
1
.
year
.
ago
)
@runner1
=
create
(
:ci_runner
,
:instance
,
contacted_at:
1
.
year
.
ago
)
@runner2
=
FactoryBot
.
create
(
:ci_runner
,
:shared
,
contacted_at:
1
.
second
.
ago
)
@runner2
=
create
(
:ci_runner
,
:instance
,
contacted_at:
1
.
second
.
ago
)
end
end
it
{
is_expected
.
to
eq
([
@runner2
])}
it
{
is_expected
.
to
eq
([
@runner2
])}
end
end
describe
'#online?'
do
describe
'#online?'
do
let
(
:runner
)
{
FactoryBot
.
create
(
:ci_runner
,
:shared
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
subject
{
runner
.
online?
}
subject
{
runner
.
online?
}
...
@@ -299,21 +302,20 @@ describe Ci::Runner do
...
@@ -299,21 +302,20 @@ describe Ci::Runner do
end
end
describe
'#can_pick?'
do
describe
'#can_pick?'
do
l
et
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
s
et
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
tag_list:
tag_list
,
run_untagged:
run_untagged
)
}
let
(
:runner_project
)
{
build
.
project
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
runner_project
],
tag_list:
tag_list
,
run_untagged:
run_untagged
)
}
let
(
:tag_list
)
{
[]
}
let
(
:tag_list
)
{
[]
}
let
(
:run_untagged
)
{
true
}
let
(
:run_untagged
)
{
true
}
subject
{
runner
.
can_pick?
(
build
)
}
subject
{
runner
.
can_pick?
(
build
)
}
before
do
build
.
project
.
runners
<<
runner
end
context
'a different runner'
do
context
'a different runner'
do
let
(
:other_project
)
{
create
(
:project
)
}
let
(
:other_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
other_project
],
tag_list:
tag_list
,
run_untagged:
run_untagged
)
}
it
'cannot handle builds'
do
it
'cannot handle builds'
do
other_runner
=
create
(
:ci_runner
)
expect
(
other_runner
.
can_pick?
(
build
)).
to
be_falsey
expect
(
other_runner
.
can_pick?
(
build
)).
to
be_falsey
end
end
end
end
...
@@ -367,18 +369,14 @@ describe Ci::Runner do
...
@@ -367,18 +369,14 @@ describe Ci::Runner do
end
end
context
'when runner is shared'
do
context
'when runner is shared'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:shared
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
before
do
build
.
project
.
runners
=
[]
end
it
'can handle builds'
do
it
'can handle builds'
do
expect
(
runner
.
can_pick?
(
build
)).
to
be_truthy
expect
(
runner
.
can_pick?
(
build
)).
to
be_truthy
end
end
context
'when runner is locked'
do
context
'when runner is locked'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:
shared
,
locked:
true
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:
instance
,
locked:
true
)
}
it
'can handle builds'
do
it
'can handle builds'
do
expect
(
runner
.
can_pick?
(
build
)).
to
be_truthy
expect
(
runner
.
can_pick?
(
build
)).
to
be_truthy
...
@@ -393,10 +391,8 @@ describe Ci::Runner do
...
@@ -393,10 +391,8 @@ describe Ci::Runner do
end
end
end
end
context
'when runner is not assigned to a project'
do
context
'when runner is assigned to another project'
do
before
do
let
(
:runner_project
)
{
create
(
:project
)
}
build
.
project
.
runners
=
[]
end
it
'cannot handle builds'
do
it
'cannot handle builds'
do
expect
(
runner
.
can_pick?
(
build
)).
to
be_falsey
expect
(
runner
.
can_pick?
(
build
)).
to
be_falsey
...
@@ -404,10 +400,8 @@ describe Ci::Runner do
...
@@ -404,10 +400,8 @@ describe Ci::Runner do
end
end
context
'when runner is assigned to a group'
do
context
'when runner is assigned to a group'
do
before
do
let
(
:group
)
{
create
(
:group
,
projects:
[
build
.
project
])
}
build
.
project
.
runners
=
[]
let
(
:runner
)
{
create
(
:ci_runner
,
:group
,
tag_list:
tag_list
,
run_untagged:
run_untagged
,
groups:
[
group
])
}
runner
.
groups
<<
create
(
:group
,
projects:
[
build
.
project
])
end
it
'can handle builds'
do
it
'can handle builds'
do
expect
(
runner
.
can_pick?
(
build
)).
to
be_truthy
expect
(
runner
.
can_pick?
(
build
)).
to
be_truthy
...
@@ -461,7 +455,7 @@ describe Ci::Runner do
...
@@ -461,7 +455,7 @@ describe Ci::Runner do
end
end
describe
'#status'
do
describe
'#status'
do
let
(
:runner
)
{
FactoryBot
.
create
(
:ci_runner
,
:shared
,
contacted_at:
1
.
second
.
ago
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:instance
,
contacted_at:
1
.
second
.
ago
)
}
subject
{
runner
.
status
}
subject
{
runner
.
status
}
...
@@ -618,19 +612,36 @@ describe Ci::Runner do
...
@@ -618,19 +612,36 @@ describe Ci::Runner do
end
end
describe
'.assignable_for'
do
describe
'.assignable_for'
do
let!
(
:unlocked_project_runner
)
{
create
(
:ci_runner
,
runner_type: :project_type
,
projects:
[
project
])
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
])
}
let!
(
:locked_project_runner
)
{
create
(
:ci_runner
,
runner_type: :project_type
,
locked:
true
,
projects:
[
project
])
}
let!
(
:group_runner
)
{
create
(
:ci_runner
,
runner_type: :group_type
)
}
let!
(
:instance_runner
)
{
create
(
:ci_runner
,
:shared
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:another_project
)
{
create
(
:project
)
}
let
(
:another_project
)
{
create
(
:project
)
}
context
'with already assigned project'
do
context
'with shared runners'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
context
'does not give owned runner'
do
subject
{
described_class
.
assignable_for
(
project
)
}
it
{
is_expected
.
to
be_empty
}
end
context
'does not give shared runner'
do
subject
{
described_class
.
assignable_for
(
another_project
)
}
it
{
is_expected
.
to
be_empty
}
end
end
context
'with unlocked runner'
do
context
'does not give owned runner'
do
subject
{
described_class
.
assignable_for
(
project
)
}
subject
{
described_class
.
assignable_for
(
project
)
}
it
{
is_expected
.
to
be_empty
}
it
{
is_expected
.
to
be_empty
}
end
end
it
{
is_expected
.
to
be_empty
}
end
context
'with a different project'
do
context
'with a different project'
do
subject
{
described_class
.
assignable_for
(
another_project
)
}
subject
{
described_class
.
assignable_for
(
another_project
)
}
...
@@ -643,19 +654,16 @@ describe Ci::Runner do
...
@@ -643,19 +654,16 @@ describe Ci::Runner do
describe
"belongs_to_one_project?"
do
describe
"belongs_to_one_project?"
do
it
"returns false if there are two projects runner assigned to"
do
it
"returns false if there are two projects runner assigned to"
do
runner
=
FactoryBot
.
create
(
:ci_runner
)
project1
=
create
(
:project
)
project
=
FactoryBot
.
create
(
:project
)
project2
=
create
(
:project
)
project1
=
FactoryBot
.
create
(
:project
)
runner
=
create
(
:ci_runner
,
:project
,
projects:
[
project1
,
project2
])
project
.
runners
<<
runner
project1
.
runners
<<
runner
expect
(
runner
.
belongs_to_one_project?
).
to
be_falsey
expect
(
runner
.
belongs_to_one_project?
).
to
be_falsey
end
end
it
"returns true"
do
it
"returns true"
do
runner
=
FactoryBot
.
create
(
:ci_runner
)
project
=
create
(
:project
)
project
=
FactoryBot
.
create
(
:project
)
runner
=
create
(
:ci_runner
,
:project
,
projects:
[
project
])
project
.
runners
<<
runner
expect
(
runner
.
belongs_to_one_project?
).
to
be_truthy
expect
(
runner
.
belongs_to_one_project?
).
to
be_truthy
end
end
...
@@ -705,14 +713,14 @@ describe Ci::Runner do
...
@@ -705,14 +713,14 @@ describe Ci::Runner do
subject
{
runner
.
assigned_to_group?
}
subject
{
runner
.
assigned_to_group?
}
context
'when project runner'
do
context
'when project runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
description:
'Project runner'
,
projects:
[
project
])
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
description:
'Project runner'
,
projects:
[
project
])
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'when shared runner'
do
context
'when shared runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:
shared
,
description:
'Shared runner'
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:
instance
,
description:
'Shared runner'
)
}
it
{
is_expected
.
to
be_falsey
}
it
{
is_expected
.
to
be_falsey
}
end
end
...
@@ -740,7 +748,7 @@ describe Ci::Runner do
...
@@ -740,7 +748,7 @@ describe Ci::Runner do
end
end
context
'when project runner'
do
context
'when project runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
description:
'Project runner'
,
projects:
[
project
])
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
description:
'Project runner'
,
projects:
[
project
])
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:project
)
{
create
(
:project
)
}
it
{
is_expected
.
to
be_truthy
}
it
{
is_expected
.
to
be_truthy
}
...
...
spec/models/project_spec.rb
View file @
051f385e
...
@@ -1177,8 +1177,8 @@ describe Project do
...
@@ -1177,8 +1177,8 @@ describe Project do
describe
'#any_runners?'
do
describe
'#any_runners?'
do
context
'shared runners'
do
context
'shared runners'
do
let
(
:project
)
{
create
(
:project
,
shared_runners_enabled:
shared_runners_enabled
)
}
let
(
:project
)
{
create
(
:project
,
shared_runners_enabled:
shared_runners_enabled
)
}
let
(
:specific_runner
)
{
create
(
:ci_runner
)
}
let
(
:specific_runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
]
)
}
let
(
:shared_runner
)
{
create
(
:ci_runner
,
:
shared
)
}
let
(
:shared_runner
)
{
create
(
:ci_runner
,
:
instance
)
}
context
'for shared runners disabled'
do
context
'for shared runners disabled'
do
let
(
:shared_runners_enabled
)
{
false
}
let
(
:shared_runners_enabled
)
{
false
}
...
@@ -1188,7 +1188,7 @@ describe Project do
...
@@ -1188,7 +1188,7 @@ describe Project do
end
end
it
'has a specific runner'
do
it
'has a specific runner'
do
project
.
runners
<<
specific_runner
specific_runner
expect
(
project
.
any_runners?
).
to
be_truthy
expect
(
project
.
any_runners?
).
to
be_truthy
end
end
...
@@ -1200,13 +1200,13 @@ describe Project do
...
@@ -1200,13 +1200,13 @@ describe Project do
end
end
it
'checks the presence of specific runner'
do
it
'checks the presence of specific runner'
do
project
.
runners
<<
specific_runner
specific_runner
expect
(
project
.
any_runners?
{
|
runner
|
runner
==
specific_runner
}).
to
be_truthy
expect
(
project
.
any_runners?
{
|
runner
|
runner
==
specific_runner
}).
to
be_truthy
end
end
it
'returns false if match cannot be found'
do
it
'returns false if match cannot be found'
do
project
.
runners
<<
specific_runner
specific_runner
expect
(
project
.
any_runners?
{
false
}).
to
be_falsey
expect
(
project
.
any_runners?
{
false
}).
to
be_falsey
end
end
...
...
spec/models/user_spec.rb
View file @
051f385e
...
@@ -1858,8 +1858,7 @@ describe User do
...
@@ -1858,8 +1858,7 @@ describe User do
describe
'#ci_owned_runners'
do
describe
'#ci_owned_runners'
do
let
(
:user
)
{
create
(
:user
)
}
let
(
:user
)
{
create
(
:user
)
}
let
(
:runner_1
)
{
create
(
:ci_runner
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
])
}
let
(
:runner_2
)
{
create
(
:ci_runner
)
}
context
'without any projects nor groups'
do
context
'without any projects nor groups'
do
let!
(
:project
)
{
create
(
:project
,
runners:
[
runner_1
])
}
let!
(
:project
)
{
create
(
:project
,
runners:
[
runner_1
])
}
...
...
spec/requests/api/runner_spec.rb
View file @
051f385e
...
@@ -262,16 +262,12 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
...
@@ -262,16 +262,12 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
describe
'/api/v4/jobs'
do
describe
'/api/v4/jobs'
do
let
(
:project
)
{
create
(
:project
,
shared_runners_enabled:
false
)
}
let
(
:project
)
{
create
(
:project
,
shared_runners_enabled:
false
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
,
ref:
'master'
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline_without_jobs
,
project:
project
,
ref:
'master'
)
}
let
(
:runner
)
{
create
(
:ci_runner
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
]
)
}
let
(
:job
)
do
let
(
:job
)
do
create
(
:ci_build
,
:artifacts
,
:extended_options
,
create
(
:ci_build
,
:artifacts
,
:extended_options
,
pipeline:
pipeline
,
name:
'spinach'
,
stage:
'test'
,
stage_idx:
0
,
commands:
"ls
\n
date"
)
pipeline:
pipeline
,
name:
'spinach'
,
stage:
'test'
,
stage_idx:
0
,
commands:
"ls
\n
date"
)
end
end
before
do
project
.
runners
<<
runner
end
describe
'POST /api/v4/jobs/request'
do
describe
'POST /api/v4/jobs/request'
do
let!
(
:last_update
)
{}
let!
(
:last_update
)
{}
let!
(
:new_update
)
{
}
let!
(
:new_update
)
{
}
...
@@ -379,7 +375,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
...
@@ -379,7 +375,7 @@ describe API::Runner, :clean_gitlab_redis_shared_state do
end
end
context
'when shared runner requests job for project without shared_runners_enabled'
do
context
'when shared runner requests job for project without shared_runners_enabled'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:
shared
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:
instance
)
}
it_behaves_like
'no jobs available'
it_behaves_like
'no jobs available'
end
end
...
...
spec/requests/api/runners_spec.rb
View file @
051f385e
...
@@ -11,7 +11,7 @@ describe API::Runners do
...
@@ -11,7 +11,7 @@ describe API::Runners do
let
(
:group
)
{
create
(
:group
).
tap
{
|
group
|
group
.
add_owner
(
user
)
}
}
let
(
:group
)
{
create
(
:group
).
tap
{
|
group
|
group
.
add_owner
(
user
)
}
}
let
(
:group2
)
{
create
(
:group
).
tap
{
|
group
|
group
.
add_owner
(
user
)
}
}
let
(
:group2
)
{
create
(
:group
).
tap
{
|
group
|
group
.
add_owner
(
user
)
}
}
let!
(
:shared_runner
)
{
create
(
:ci_runner
,
:
shared
,
description:
'Shared runner'
)
}
let!
(
:shared_runner
)
{
create
(
:ci_runner
,
:
instance
,
description:
'Shared runner'
)
}
let!
(
:unused_project_runner
)
{
create
(
:ci_runner
)
}
let!
(
:unused_project_runner
)
{
create
(
:ci_runner
)
}
let!
(
:project_runner
)
do
let!
(
:project_runner
)
do
...
...
spec/serializers/runner_entity_spec.rb
View file @
051f385e
require
'spec_helper'
require
'spec_helper'
describe
RunnerEntity
do
describe
RunnerEntity
do
let
(
:runner
)
{
create
(
:ci_runner
,
:specific
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
])
}
let
(
:entity
)
{
described_class
.
new
(
runner
,
request:
request
,
current_user:
user
)
}
let
(
:entity
)
{
described_class
.
new
(
runner
,
request:
request
,
current_user:
user
)
}
let
(
:request
)
{
double
(
'request'
)
}
let
(
:request
)
{
double
(
'request'
)
}
let
(
:project
)
{
create
(
:project
)
}
let
(
:user
)
{
create
(
:admin
)
}
let
(
:user
)
{
create
(
:admin
)
}
before
do
before
do
...
...
spec/services/ci/register_job_service_spec.rb
View file @
051f385e
...
@@ -292,7 +292,7 @@ module Ci
...
@@ -292,7 +292,7 @@ module Ci
end
end
context
'when access_level of runner is not_protected'
do
context
'when access_level of runner is not_protected'
do
let!
(
:specific_runner
)
{
create
(
:ci_runner
,
:
specific
)
}
let!
(
:specific_runner
)
{
create
(
:ci_runner
,
:
project
,
projects:
[
project
]
)
}
context
'when a job is protected'
do
context
'when a job is protected'
do
let!
(
:pending_job
)
{
create
(
:ci_build
,
:protected
,
pipeline:
pipeline
)
}
let!
(
:pending_job
)
{
create
(
:ci_build
,
:protected
,
pipeline:
pipeline
)
}
...
...
spec/services/ci/update_build_queue_service_spec.rb
View file @
051f385e
...
@@ -6,13 +6,9 @@ describe Ci::UpdateBuildQueueService do
...
@@ -6,13 +6,9 @@ describe Ci::UpdateBuildQueueService do
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
context
'when updating specific runners'
do
context
'when updating specific runners'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:project
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:project
,
projects:
[
project
]
)
}
context
'when there is a runner that can pick build'
do
context
'when there is a runner that can pick build'
do
before
do
build
.
project
.
runners
<<
runner
end
it
'ticks runner queue value'
do
it
'ticks runner queue value'
do
expect
{
subject
.
execute
(
build
)
}.
to
change
{
runner
.
ensure_runner_queue_value
}
expect
{
subject
.
execute
(
build
)
}.
to
change
{
runner
.
ensure_runner_queue_value
}
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