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
a6bfa4b8
Commit
a6bfa4b8
authored
Nov 21, 2017
by
ayufanpl
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests
parent
29f148a2
Changes
13
Hide whitespace changes
Inline
Side-by-side
Showing
13 changed files
with
404 additions
and
7 deletions
+404
-7
ee/app/controllers/profiles/pipeline_quota_controller.rb
ee/app/controllers/profiles/pipeline_quota_controller.rb
+0
-0
ee/app/models/ee/namespace.rb
ee/app/models/ee/namespace.rb
+9
-1
ee/app/services/update_build_minutes_service.rb
ee/app/services/update_build_minutes_service.rb
+1
-1
spec/ee/spec/features/groups/pipeline_quota_spec.rb
spec/ee/spec/features/groups/pipeline_quota_spec.rb
+50
-2
spec/ee/spec/features/profiles/pipeline_quota_spec.rb
spec/ee/spec/features/profiles/pipeline_quota_spec.rb
+0
-0
spec/ee/spec/models/ee/namespace_spec.rb
spec/ee/spec/models/ee/namespace_spec.rb
+120
-0
spec/ee/spec/models/ee/project_spec.rb
spec/ee/spec/models/ee/project_spec.rb
+31
-3
spec/ee/spec/services/ee/ci/register_job_service_spec.rb
spec/ee/spec/services/ee/ci/register_job_service_spec.rb
+60
-0
spec/ee/spec/views/admin/groups/_form.html.haml_spec.rb
spec/ee/spec/views/admin/groups/_form.html.haml_spec.rb
+56
-0
spec/ee/support/shared_runners_minutes_feature_flag.rb
spec/ee/support/shared_runners_minutes_feature_flag.rb
+6
-0
spec/lib/gitlab/group_hierarchy_spec.rb
spec/lib/gitlab/group_hierarchy_spec.rb
+14
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+23
-0
spec/services/update_build_minutes_service_spec.rb
spec/services/update_build_minutes_service_spec.rb
+34
-0
No files found.
app/controllers/profiles/pipeline_quota_controller.rb
→
ee/
app/controllers/profiles/pipeline_quota_controller.rb
View file @
a6bfa4b8
File moved
ee/app/models/ee/namespace.rb
View file @
a6bfa4b8
...
...
@@ -94,7 +94,7 @@ module EE
end
def
shared_runner_minutes_supported?
if
parent_id
if
has_parent?
Feature
.
enabled?
(
:shared_runner_minutes_on_subnamespace
)
else
true
...
...
@@ -117,6 +117,14 @@ module EE
shared_runners_minutes
.
to_i
>=
actual_shared_runners_minutes_limit
end
def
shared_runners_enabled?
if
Feature
.
enabled?
(
:shared_runner_minutes_on_subnamespace
)
projects
.
with_shared_runners
.
any?
else
all_projects
.
with_shared_runners
.
any?
end
end
# These helper methods are required to not break the Namespace API.
def
plan
=
(
plan_name
)
if
plan_name
.
is_a?
(
String
)
...
...
ee/app/services/update_build_minutes_service.rb
View file @
a6bfa4b8
...
...
@@ -18,7 +18,7 @@ class UpdateBuildMinutesService < BaseService
end
def
project_statistics
project
.
statistics
||
project
.
create_statistics
(
namespace:
namespace
)
project
.
statistics
||
project
.
create_statistics
(
namespace:
project
.
namespace
)
end
def
namespace
...
...
spec/features/groups/pipeline_quota_spec.rb
→
spec/
ee/spec/
features/groups/pipeline_quota_spec.rb
View file @
a6bfa4b8
...
...
@@ -95,8 +95,56 @@ feature 'Groups > Pipeline Quota' do
end
page
.
within
(
'.pipeline-project-metrics'
)
do
expect
(
page
).
to
have_content
(
project
.
name
)
expect
(
page
).
not_to
have_content
(
other_project
.
name
)
expect
(
page
).
to
have_content
(
project
.
full_name
)
expect
(
page
).
not_to
have_content
(
other_project
.
full_name
)
end
end
end
context
'with shared_runner_minutes_on_subnamespace enabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
true
)
end
context
'when accessing group with subgroups'
do
let
(
:group
)
{
create
(
:group
,
:with_used_build_minutes_limit
)
}
let!
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
let!
(
:subproject
)
{
create
(
:project
,
namespace:
subgroup
,
shared_runners_enabled:
true
)
}
it
'does not show project of subgroup'
do
visit_pipeline_quota_page
expect
(
page
).
to
have_content
(
project
.
full_name
)
expect
(
page
).
not_to
have_content
(
subproject
.
full_name
)
end
end
end
context
'with shared_runner_minutes_on_subnamespace disabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
context
'when accessing subgroup'
do
let
(
:root_ancestor
)
{
create
(
:group
)
}
let
(
:group
)
{
create
(
:group
,
:with_used_build_minutes_limit
,
parent:
root_ancestor
)
}
it
'does not show subproject'
do
visit_pipeline_quota_page
expect
(
page
).
to
have_http_status
(
:not_found
)
end
end
context
'when accesing root group'
do
let!
(
:subgroup
)
{
create
(
:group
,
parent:
group
)
}
let!
(
:subproject
)
{
create
(
:project
,
namespace:
subgroup
,
shared_runners_enabled:
true
)
}
it
'does show projects of subgroup'
do
visit_pipeline_quota_page
expect
(
page
).
to
have_content
(
project
.
full_name
)
expect
(
page
).
to
have_content
(
subproject
.
full_name
)
end
end
end
...
...
spec/features/profiles/pipeline_quota_spec.rb
→
spec/
ee/spec/
features/profiles/pipeline_quota_spec.rb
View file @
a6bfa4b8
File moved
spec/ee/spec/models/ee/namespace_spec.rb
View file @
a6bfa4b8
...
...
@@ -63,6 +63,34 @@ describe Namespace do
end
end
end
describe
'#validate_shared_runner_minutes_support'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
context
'when changing :shared_runners_minutes_limit'
do
before
do
namespace
.
shared_runners_minutes_limit
=
100
end
context
'when group is subgroup'
do
set
(
:root_ancestor
)
{
create
(
:group
)
}
let
(
:namespace
)
{
create
(
:namespace
,
parent:
root_ancestor
)
}
it
'is invalid'
do
expect
(
namespace
).
not_to
be_valid
expect
(
namespace
.
errors
[
:shared_runners_minutes_limit
]).
to
include
(
'is not supported for this namespace'
)
end
end
context
'when group is root'
do
it
'is valid'
do
expect
(
namespace
).
to
be_valid
end
end
end
end
end
describe
'#move_dir'
do
...
...
@@ -295,6 +323,42 @@ describe Namespace do
end
end
describe
'#shared_runner_minutes_supported?'
do
subject
{
namespace
.
shared_runner_minutes_supported?
}
context
'when is subgroup'
do
before
do
namespace
.
parent
=
build
(
:group
)
end
context
'when shared_runner_minutes_on_subnamespace is enabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
true
)
end
it
'returns true'
do
is_expected
.
to
eq
(
true
)
end
end
context
'when shared_runner_minutes_on_subnamespace is disalbed'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
it
'returns false'
do
is_expected
.
to
eq
(
false
)
end
end
end
context
'when is root'
do
it
'returns true'
do
is_expected
.
to
eq
(
true
)
end
end
end
describe
'#shared_runners_minutes_limit_enabled?'
do
subject
{
namespace
.
shared_runners_minutes_limit_enabled?
}
...
...
@@ -315,6 +379,15 @@ describe Namespace do
end
it
{
is_expected
.
to
be_truthy
}
context
'when is subgroup'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
namespace
.
parent
=
build
(
:group
)
end
it
{
is_expected
.
to
be_falsey
}
end
end
end
...
...
@@ -323,6 +396,49 @@ describe Namespace do
end
end
describe
'#shared_runners_enabled?'
do
subject
{
namespace
.
shared_runners_enabled?
}
context
'subgroup with shared runners enabled project'
do
let
(
:subgroup
)
{
create
(
:group
,
parent:
namespace
)
}
let!
(
:subproject
)
{
create
(
:project
,
namespace:
subgroup
,
shared_runners_enabled:
true
)
}
context
'when shared_runner_minutes_on_subnamespace is enabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
true
)
end
it
"returns false"
do
is_expected
.
to
eq
(
false
)
end
end
context
'when shared_runner_minutes_on_subnamespace is disabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
it
"returns true"
do
is_expected
.
to
eq
(
true
)
end
end
end
context
'group with shared runners enabled project'
do
let!
(
:project
)
{
create
(
:project
,
namespace:
namespace
,
shared_runners_enabled:
true
)
}
it
"returns true"
do
is_expected
.
to
eq
(
true
)
end
end
context
'group without projects'
do
it
"returns false"
do
is_expected
.
to
eq
(
false
)
end
end
end
describe
'#shared_runners_minutes_used?'
do
subject
{
namespace
.
shared_runners_minutes_used?
}
...
...
@@ -400,4 +516,8 @@ describe Namespace do
end
end
end
describe
'#validate_shared_runner_minutes_support'
do
end
end
spec/ee/spec/models/ee/project_spec.rb
View file @
a6bfa4b8
...
...
@@ -8,9 +8,9 @@ describe Project do
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds_last_reset
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:actual_shared_runners_minutes_limit
).
to
(
:namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_limit_enabled?
).
to
(
:namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_used?
).
to
(
:namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:actual_shared_runners_minutes_limit
).
to
(
:
shared_runners_limit_
namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_limit_enabled?
).
to
(
:
shared_runners_limit_
namespace
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_used?
).
to
(
:
shared_runners_limit_
namespace
)
}
it
{
is_expected
.
to
have_one
(
:mirror_data
).
class_name
(
'ProjectMirrorData'
)
}
it
{
is_expected
.
to
have_many
(
:path_locks
)
}
...
...
@@ -532,6 +532,34 @@ describe Project do
end
end
describe
'#shared_runners_limit_namespace'
do
set
(
:root_ancestor
)
{
create
(
:group
)
}
set
(
:group
)
{
create
(
:group
,
parent:
root_ancestor
)
}
let
(
:project
)
{
create
(
:project
,
namespace:
group
)
}
subject
{
project
.
shared_runners_limit_namespace
}
context
'when shared_runner_minutes_on_subnamespace is enabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
true
)
end
it
'returns parent namespace'
do
is_expected
.
to
eq
(
group
)
end
end
context
'when shared_runner_minutes_on_subnamespace is disabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
it
'returns root namespace'
do
is_expected
.
to
eq
(
root_ancestor
)
end
end
end
describe
'#shared_runners_minutes_limit_enabled?'
do
let
(
:project
)
{
create
(
:project
)
}
...
...
spec/ee/spec/services/ee/ci/register_job_service_spec.rb
View file @
a6bfa4b8
...
...
@@ -62,6 +62,66 @@ module Ci
end
end
end
context
'when group is subgroup'
do
let!
(
:root_ancestor
)
{
create
(
:group
,
shared_runners_minutes_limit:
10
)
}
let!
(
:group
)
{
create
(
:group
,
parent:
root_ancestor
,
shared_runners_minutes_limit:
10
)
}
let!
(
:project
)
{
create
:project
,
shared_runners_enabled:
true
,
group:
group
}
let
(
:build
)
{
execute
(
shared_runner
)
}
context
'when shared_runner_minutes_on_subnamespace is enabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
true
)
end
it
"does return a build"
do
expect
(
build
).
not_to
be_nil
end
context
'when we are over limit on subnamespace'
do
before
do
group
.
create_namespace_statistics
(
shared_runners_seconds:
6001
)
end
it
"does not return a build"
do
expect
(
build
).
to
be_nil
end
end
end
context
'when shared_runner_minutes_on_subnamespace is disabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
it
"does return a build"
do
expect
(
build
).
not_to
be_nil
end
context
'when we are over limit on subnamespace'
do
before
do
group
.
create_namespace_statistics
(
shared_runners_seconds:
6001
)
end
it
"limit is ignored and build is returned"
do
expect
(
build
).
not_to
be_nil
end
end
context
'when we are over limit on root namespace'
do
before
do
root_ancestor
.
create_namespace_statistics
(
shared_runners_seconds:
6001
)
end
it
"does not return a build"
do
expect
(
build
).
to
be_nil
end
end
end
end
end
def
execute
(
runner
)
...
...
spec/ee/spec/views/admin/groups/_form.html.haml_spec.rb
0 → 100644
View file @
a6bfa4b8
require
'spec_helper'
describe
'admin/groups/_form'
do
set
(
:admin
)
{
create
(
:admin
)
}
before
do
assign
(
:group
,
group
)
allow
(
view
).
to
receive
(
:can?
)
{
true
}
allow
(
view
).
to
receive
(
:current_user
)
{
admin
}
allow
(
view
).
to
receive
(
:visibility_level
)
{
group
.
visibility_level
}
end
describe
'when :shared_runner_minutes_on_subnamespace is enabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
true
)
end
context
'when sub group is used'
do
let
(
:root_ancestor
)
{
create
(
:group
)
}
let
(
:group
)
{
build
(
:group
,
parent:
root_ancestor
)
}
it
'renders shared_runners_minutes_setting'
do
render
expect
(
rendered
).
to
render_template
(
'namespaces/_shared_runners_minutes_setting'
)
end
end
end
describe
'when :shared_runner_minutes_on_subnamespace is disabled'
do
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
context
'when sub group is used'
do
let
(
:root_ancestor
)
{
create
(
:group
)
}
let
(
:group
)
{
build
(
:group
,
parent:
root_ancestor
)
}
it
'does not render shared_runners_minutes_setting'
do
render
expect
(
rendered
).
not_to
render_template
(
'namespaces/_shared_runners_minutes_setting'
)
end
end
context
'when root group is used'
do
let
(
:group
)
{
build
(
:group
)
}
it
'does not render shared_runners_minutes_setting'
do
render
expect
(
rendered
).
to
render_template
(
'namespaces/_shared_runners_minutes_setting'
)
end
end
end
end
spec/ee/support/shared_runners_minutes_feature_flag.rb
0 → 100644
View file @
a6bfa4b8
RSpec
.
configure
do
|
config
|
config
.
before
(
:all
)
do
puts
"this feature is by default disabled"
Feature
.
get
(
:shared_runner_minutes_on_subnamespace
).
disable
end
end
spec/lib/gitlab/group_hierarchy_spec.rb
View file @
a6bfa4b8
...
...
@@ -83,6 +83,20 @@ describe Gitlab::GroupHierarchy, :postgresql do
end
end
describe
'#root'
do
it
'includes only the roots'
do
relation
=
described_class
.
new
(
Group
.
where
(
id:
child2
)).
roots
expect
(
relation
).
to
contain_exactly
(
parent
)
end
it
'when quering parent it includes parent'
do
relation
=
described_class
.
new
(
Group
.
where
(
id:
parent
)).
roots
expect
(
relation
).
to
contain_exactly
(
parent
)
end
end
describe
'#all_groups'
do
let
(
:relation
)
do
described_class
.
new
(
Group
.
where
(
id:
child1
.
id
)).
all_groups
...
...
spec/models/project_spec.rb
View file @
a6bfa4b8
...
...
@@ -3474,4 +3474,27 @@ describe Project do
expect
(
project
.
wiki_repository_exists?
).
to
eq
(
false
)
end
end
describe
'#root_namespace'
do
let
(
:project
)
{
build
(
:project
,
namespace:
parent
)
}
subject
{
project
.
root_namespace
}
context
'when namespace has parent group'
do
let
(
:root_ancestor
)
{
create
(
:group
)
}
let
(
:parent
)
{
build
(
:group
,
parent:
root_ancestor
)
}
it
'returns root ancestor'
do
is_expected
.
to
eq
(
root_ancestor
)
end
end
context
'when namespace is root ancestor'
do
let
(
:parent
)
{
build
(
:group
)
}
it
'returns current namespace'
do
is_expected
.
to
eq
(
parent
)
end
end
end
end
spec/services/update_build_minutes_service_spec.rb
View file @
a6bfa4b8
...
...
@@ -42,6 +42,40 @@ describe UpdateBuildMinutesService do
.
to
eq
(
100
+
build
.
duration
.
to_i
)
end
end
context
'when namespace is subgroup'
do
let
(
:root_ancestor
)
{
create
(
:group
,
shared_runners_minutes_limit:
100
)
}
context
'when shared_runner_minutes_on_subnamespace is enabled'
do
let
(
:namespace
)
{
create
(
:namespace
,
parent:
root_ancestor
,
shared_runners_minutes_limit:
100
)
}
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
true
)
end
it
'creates a statistics in current namespace'
do
subject
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_seconds
)
.
to
eq
(
build
.
duration
.
to_i
)
end
end
context
'when shared_runner_minutes_on_subnamespace is disabled'
do
let
(
:namespace
)
{
create
(
:namespace
,
parent:
root_ancestor
)
}
before
do
stub_feature_flags
(
shared_runner_minutes_on_subnamespace:
false
)
end
it
'creates a statistics in root namespace'
do
subject
expect
(
root_ancestor
.
namespace_statistics
.
reload
.
shared_runners_seconds
)
.
to
eq
(
build
.
duration
.
to_i
)
end
end
end
end
context
'for specific runner'
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