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
aa20cedc
Commit
aa20cedc
authored
Jan 19, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Abstract EE-code into separate mixins
parent
0b6ad31c
Changes
6
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
80 additions
and
72 deletions
+80
-72
app/models/project_metrics.rb
app/models/project_metrics.rb
+0
-5
app/services/ee/ci/register_build_service.rb
app/services/ee/ci/register_build_service.rb
+6
-4
spec/factories/namespace_statistics.rb
spec/factories/namespace_statistics.rb
+0
-0
spec/factories/project_metrics.rb
spec/factories/project_metrics.rb
+0
-5
spec/services/ci/register_build_service_spec.rb
spec/services/ci/register_build_service_spec.rb
+2
-58
spec/services/ee/ci/register_build_service_spec.rb
spec/services/ee/ci/register_build_service_spec.rb
+72
-0
No files found.
app/models/project_metrics.rb
deleted
100644 → 0
View file @
0b6ad31c
class
ProjectMetrics
<
ActiveRecord
::
Base
belongs_to
:project
validates
:project
,
presence:
true
end
app/services/ee/ci/register_build_service.rb
View file @
aa20cedc
module
EE
module
Ci
# This class responsible for assigning
# proper pending build to runner on runner API request
class
RegisterBuildService
# RegisterBuildService EE mixin
#
# This module is intended to encapsulate EE-specific service logic
# and be included in the `RegisterBuildService` service
module
RegisterBuildService
extend
ActiveSupport
::
Prependable
def
builds_for_shared_runner
...
...
@@ -15,7 +17,7 @@ module EE
end
def
builds_check_limit
Namespace
.
reorder
(
nil
).
::
Namespace
.
reorder
(
nil
).
where
(
'namespaces.id = projects.namespace_id'
).
joins
(
'LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id'
).
where
(
'COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR '
\
...
...
spec/factories/namespace_
metr
ics.rb
→
spec/factories/namespace_
statist
ics.rb
View file @
aa20cedc
File moved
spec/factories/project_metrics.rb
deleted
100644 → 0
View file @
0b6ad31c
FactoryGirl
.
define
do
factory
:project_metrics
do
project
factory: :empty_project
end
end
spec/services/ci/register_build_service_spec.rb
View file @
aa20cedc
...
...
@@ -130,75 +130,19 @@ module Ci
end
end
context
'for project with shared runners when global minutes limit is set'
do
before
do
project
.
update
(
shared_runners_enabled:
true
)
stub_application_setting
(
shared_runners_minutes:
500
)
end
context
'allow to pick builds'
do
let
(
:build
)
{
execute
(
shared_runner
)
}
it
{
expect
(
build
).
to
be_kind_of
(
Build
)
}
end
context
'when over the global quota'
do
before
do
project
.
namespace
.
create_namespace_metrics
(
shared_runners_minutes:
600
)
end
let
(
:build
)
{
execute
(
shared_runner
)
}
it
"does not return a build"
do
expect
(
build
).
to
be_nil
end
context
'when project is public'
do
before
do
project
.
update
(
visibility_level:
Project
::
PUBLIC
)
end
it
"does return the build"
do
expect
(
build
).
to
be_kind_of
(
Build
)
end
end
context
'when namespace limit is set to unlimited'
do
before
do
project
.
namespace
.
update
(
shared_runners_minutes_limit:
0
)
end
it
"does return the build"
do
expect
(
build
).
to
be_kind_of
(
Build
)
end
end
context
'when namespace quota is bigger than a global one'
do
before
do
project
.
namespace
.
update
(
shared_runners_minutes_limit:
1000
)
end
it
"does return the build"
do
expect
(
build
).
to
be_kind_of
(
Build
)
end
end
end
end
context
'disallow shared runners'
do
before
do
project
.
update
(
shared_runners_enabled:
false
)
end
context
'shared runner'
do
let
(
:build
)
{
execute
(
shared_runner
)
}
let
(
:build
)
{
service
.
execute
(
shared_runner
)
}
it
{
expect
(
build
).
to
be_nil
}
end
context
'specific runner'
do
let
(
:build
)
{
execute
(
specific_runner
)
}
let
(
:build
)
{
service
.
execute
(
specific_runner
)
}
it
{
expect
(
build
).
to
be_kind_of
(
Build
)
}
it
{
expect
(
build
).
to
be_valid
}
...
...
spec/services/ee/ci/register_build_service_spec.rb
0 → 100644
View file @
aa20cedc
require
'spec_helper'
module
Ci
describe
RegisterBuildService
,
services:
true
do
let!
(
:project
)
{
create
:empty_project
,
shared_runners_enabled:
false
}
let!
(
:pipeline
)
{
create
:ci_empty_pipeline
,
project:
project
}
let!
(
:pending_build
)
{
create
:ci_build
,
pipeline:
pipeline
}
let
(
:shared_runner
)
{
create
(
:ci_runner
,
:shared
)
}
describe
'#execute'
do
context
'for project with shared runners when global minutes limit is set'
do
before
do
project
.
update
(
shared_runners_enabled:
true
)
stub_application_setting
(
shared_runners_minutes:
500
)
end
context
'allow to pick builds'
do
let
(
:build
)
{
execute
(
shared_runner
)
}
it
{
expect
(
build
).
to
be_kind_of
(
Build
)
}
end
context
'when over the global quota'
do
before
do
project
.
namespace
.
create_namespace_statistics
(
shared_runners_minutes:
600
)
end
let
(
:build
)
{
execute
(
shared_runner
)
}
it
"does not return a build"
do
expect
(
build
).
to
be_nil
end
context
'when project is public'
do
before
do
project
.
update
(
visibility_level:
Project
::
PUBLIC
)
end
it
"does return the build"
do
expect
(
build
).
to
be_kind_of
(
Build
)
end
end
context
'when namespace limit is set to unlimited'
do
before
do
project
.
namespace
.
update
(
shared_runners_minutes_limit:
0
)
end
it
"does return the build"
do
expect
(
build
).
to
be_kind_of
(
Build
)
end
end
context
'when namespace quota is bigger than a global one'
do
before
do
project
.
namespace
.
update
(
shared_runners_minutes_limit:
1000
)
end
it
"does return the build"
do
expect
(
build
).
to
be_kind_of
(
Build
)
end
end
end
end
def
execute
(
runner
)
described_class
.
new
(
runner
).
execute
end
end
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