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
1dbf1e6e
Commit
1dbf1e6e
authored
Dec 20, 2016
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Update tests
parent
4f841b12
Changes
14
Show whitespace changes
Inline
Side-by-side
Showing
14 changed files
with
112 additions
and
72 deletions
+112
-72
app/helpers/groups_helper.rb
app/helpers/groups_helper.rb
+1
-1
app/models/ci/build.rb
app/models/ci/build.rb
+5
-1
app/models/project.rb
app/models/project.rb
+0
-4
app/services/update_build_minutes_service.rb
app/services/update_build_minutes_service.rb
+20
-7
app/views/admin/groups/show.html.haml
app/views/admin/groups/show.html.haml
+1
-1
app/views/projects/empty.html.haml
app/views/projects/empty.html.haml
+1
-1
app/views/projects/pipelines/index.html.haml
app/views/projects/pipelines/index.html.haml
+1
-1
app/views/projects/show.html.haml
app/views/projects/show.html.haml
+1
-1
app/views/shared/_shared_runners_minutes_limit.html.haml
app/views/shared/_shared_runners_minutes_limit.html.haml
+0
-0
spec/factories/ci/runners.rb
spec/factories/ci/runners.rb
+4
-0
spec/models/build_spec.rb
spec/models/build_spec.rb
+59
-0
spec/models/namespace_spec.rb
spec/models/namespace_spec.rb
+8
-4
spec/models/project_spec.rb
spec/models/project_spec.rb
+2
-38
spec/services/update_build_minutes_service_spec.rb
spec/services/update_build_minutes_service_spec.rb
+9
-13
No files found.
app/helpers/groups_helper.rb
View file @
1dbf1e6e
...
...
@@ -77,7 +77,7 @@ module GroupsHelper
def
group_shared_runner_limits_percent_used
(
group
)
return
0
unless
group
.
shared_runners_minutes_limit_enabled?
100
*
group
.
shared_runners_minutes
/
group
.
actual_shared_runners_minutes_limit
100
*
group
.
shared_runners_minutes
.
to_i
/
group
.
actual_shared_runners_minutes_limit
end
def
group_shared_runner_limits_progress_bar
(
group
)
...
...
app/models/ci/build.rb
View file @
1dbf1e6e
...
...
@@ -103,7 +103,7 @@ module Ci
after_transition
any
=>
[
:success
,
:failed
,
:canceled
]
do
|
build
|
build
.
run_after_commit
do
UpdateBuildMinutesService
.
new
(
project
,
nil
).
execute
(
build
)
UpdateBuildMinutesService
.
new
(
project
,
nil
).
execute
(
self
)
end
end
...
...
@@ -537,6 +537,10 @@ module Ci
Gitlab
::
Ci
::
Build
::
Credentials
::
Factory
.
new
(
self
).
create!
end
def
shared_runners_minutes_quota?
runner
&&
runner
.
shared?
&&
!
project
.
public?
end
private
def
update_artifacts_size
...
...
app/models/project.rb
View file @
1dbf1e6e
...
...
@@ -1567,10 +1567,6 @@ class Project < ActiveRecord::Base
end
end
def
shared_runners_minutes_limit_enabled?
!
public
?
&&
namespace
.
shared_runners_minutes_limit_enabled?
end
private
# Check if a reference is being done cross-project
...
...
app/services/update_build_minutes_service.rb
View file @
1dbf1e6e
class
UpdateBuildMinutesService
<
BaseService
def
execute
(
build
)
return
unless
build
.
runner
.
try
(
:shared?
)
return
unless
build
.
project
.
try
(
:shared_runners_minutes_limit_enabled?
)
return
unless
build
.
finished?
return
unless
build
.
shared_runners_minutes_quota?
return
unless
build
.
complete?
return
unless
build
.
duration
project
.
find_or_create_project_metrics
.
update_all
(
'shared_runners_minutes = shared_runners_minutes + ?'
,
build
.
duration
)
ProjectMetrics
.
update_counters
(
project_metrics
,
shared_runners_minutes:
build
.
duration
)
project
.
namespace
.
find_or_create_namespace_metrics
.
update_all
(
'shared_runners_minutes = shared_runners_minutes + ?'
,
build
.
duration
)
NamespaceMetrics
.
update_counters
(
namespace_metrics
,
shared_runners_minutes:
build
.
duration
)
end
private
def
namespace_metrics
namespace
.
namespace_metrics
||
namespace
.
create_namespace_metrics
end
def
project_metrics
project
.
project_metrics
||
project
.
create_project_metrics
end
def
namespace
project
.
namespace
end
end
app/views/admin/groups/show.html.haml
View file @
1dbf1e6e
...
...
@@ -46,7 +46,7 @@
-
if
@group
.
shared_runners_enabled?
%li
%span
.light
Shared CI Runner Q
uota:
%span
.light
Build minutes q
uota:
%strong
=
group_shared_runner_limits_quota
(
@group
)
=
link_to
icon
(
'question-circle'
),
help_page_path
(
"user/admin_area/settings/continuous_integration"
,
anchor:
"shared-runners-minutes"
)
...
...
app/views/projects/empty.html.haml
View file @
1dbf1e6e
...
...
@@ -4,7 +4,7 @@
-
if
current_user
&&
can?
(
current_user
,
:download_code
,
@project
)
=
render
'shared/no_ssh'
=
render
'shared/no_password'
=
render
'shared/shared_runner_minutes_limit'
,
project:
@project
=
render
'shared/shared_runner
s
_minutes_limit'
,
project:
@project
=
render
"home_panel"
...
...
app/views/projects/pipelines/index.html.haml
View file @
1dbf1e6e
...
...
@@ -2,7 +2,7 @@
-
page_title
"Pipelines"
=
content_for
:flash_message
do
=
render
'shared/shared_runner_minutes_limit'
,
project:
@project
=
render
'shared/shared_runner
s
_minutes_limit'
,
project:
@project
=
render
"projects/pipelines/head"
...
...
app/views/projects/show.html.haml
View file @
1dbf1e6e
...
...
@@ -8,7 +8,7 @@
-
if
current_user
&&
can?
(
current_user
,
:download_code
,
@project
)
=
render
'shared/no_ssh'
=
render
'shared/no_password'
=
render
'shared/shared_runner_minutes_limit'
,
project:
@project
=
render
'shared/shared_runner
s
_minutes_limit'
,
project:
@project
-
if
@project
.
above_size_limit?
=
render
'above_size_limit_warning'
...
...
app/views/shared/_shared_runner_minutes_limit.html.haml
→
app/views/shared/_shared_runner
s
_minutes_limit.html.haml
View file @
1dbf1e6e
File moved
spec/factories/ci/runners.rb
View file @
1dbf1e6e
...
...
@@ -12,6 +12,10 @@ FactoryGirl.define do
is_shared
true
end
trait
:specific
do
is_shared
false
end
trait
:inactive
do
active
false
end
...
...
spec/models/build_spec.rb
View file @
1dbf1e6e
...
...
@@ -1321,4 +1321,63 @@ describe Ci::Build, models: true do
.
to
be_a
Gitlab
::
Ci
::
Status
::
Build
::
Cancelable
end
end
describe
'#shared_runners_minutes_quota?'
do
subject
{
build
.
shared_runners_minutes_quota?
}
context
'for shared runner'
do
before
do
build
.
runner
=
create
(
:ci_runner
,
:shared
)
end
context
'for public project'
do
before
do
build
.
project
.
visibility_level
=
Gitlab
::
VisibilityLevel
::
PUBLIC
end
it
{
is_expected
.
to
be_falsey
}
end
context
'for internal project'
do
before
do
build
.
project
.
visibility_level
=
Gitlab
::
VisibilityLevel
::
INTERNAL
end
it
{
is_expected
.
to
be_truthy
}
end
context
'for private project'
do
before
do
build
.
project
.
visibility_level
=
Gitlab
::
VisibilityLevel
::
INTERNAL
end
it
{
is_expected
.
to
be_truthy
}
end
end
context
'with specific runner'
do
before
do
build
.
runner
=
create
(
:ci_runner
,
:specific
)
end
it
{
is_expected
.
to
be_falsey
}
end
context
'without runner'
do
it
{
is_expected
.
to
be_falsey
}
end
end
context
'updates build minutes'
do
let
(
:build
)
{
create
(
:ci_build
,
:running
,
pipeline:
pipeline
)
}
%w(success drop cancel)
.
each
do
|
event
|
it
"for event
#{
event
}
"
do
expect
(
UpdateBuildMinutesService
).
to
receive
(
:new
).
and_call_original
build
.
public_send
(
event
)
end
end
end
end
spec/models/namespace_spec.rb
View file @
1dbf1e6e
...
...
@@ -17,8 +17,8 @@ describe Namespace, models: true do
it
{
is_expected
.
to
validate_presence_of
(
:owner
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner_minutes
).
to
(
:namespace_metrics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner_last_reset
).
to
(
:namespace_metrics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner
s
_minutes
).
to
(
:namespace_metrics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner
s_minutes
_last_reset
).
to
(
:namespace_metrics
)
}
describe
"Respond to"
do
it
{
is_expected
.
to
respond_to
(
:human_name
)
}
...
...
@@ -154,7 +154,11 @@ describe Namespace, models: true do
context
'with project'
do
context
'and disabled shared runners'
do
let!
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let!
(
:project
)
do
create
(
:empty_project
,
namespace:
namespace
,
shared_runners_enabled:
false
)
end
it
{
is_expected
.
to
be_falsey
}
end
...
...
@@ -175,7 +179,7 @@ describe Namespace, models: true do
subject
{
namespace
.
actual_shared_runners_minutes_limit
}
context
'when no limit defined'
do
it
{
is_expected
.
to
be_
nil
}
it
{
is_expected
.
to
be_
zero
}
end
context
'when application settings limit is set'
do
...
...
spec/models/project_spec.rb
View file @
1dbf1e6e
...
...
@@ -74,8 +74,8 @@ describe Project, models: true do
it
{
is_expected
.
to
have_many
(
:forks
).
through
(
:forked_project_links
)
}
it
{
is_expected
.
to
have_many
(
:approver_groups
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner_minutes
).
to
(
:project_metrics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner_last_reset
).
to
(
:project_metrics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner
s
_minutes
).
to
(
:project_metrics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runner
s
_last_reset
).
to
(
:project_metrics
)
}
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
)
}
...
...
@@ -2072,42 +2072,6 @@ describe Project, models: true do
end
end
describe
'#shared_runners_minutes_limit_enabled?'
do
subject
{
project
.
shared_runners_minutes_limit_enabled?
}
context
'with limit enabled'
do
let
(
:namespace
)
{
create
(
:namespace
,
:with_build_minutes_limit
)
}
context
'for public project'
do
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
it
{
is_expected
.
to
be_truthy
}
end
context
'for internal project'
do
let
(
:project
)
{
create
(
:empty_project
,
:internal
,
namespace:
namespace
)
}
it
{
is_expected
.
to
be_falsey
}
end
context
'for private project'
do
let
(
:project
)
{
create
(
:empty_project
,
:private
,
namespace:
namespace
)
}
it
{
is_expected
.
to
be_falsey
}
end
end
context
'with limit not set'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
context
'for public project'
do
let
(
:project
)
{
create
(
:empty_project
,
:public
,
namespace:
namespace
)
}
it
{
is_expected
.
to
be_falsey
}
end
end
end
describe
'#deployment_variables'
do
context
'when project has no deployment service'
do
let
(
:project
)
{
create
(
:empty_project
)
}
...
...
spec/services/update_build_minutes_service_spec.rb
View file @
1dbf1e6e
...
...
@@ -11,7 +11,7 @@ describe UpdateBuildMinutesService, services: true do
started_at:
2
.
hours
.
ago
,
finished_at:
1
.
hour
.
ago
)
end
subject
{
described_class
.
new
.
execute
(
build
)
}
subject
{
described_class
.
new
(
project
,
nil
)
.
execute
(
build
)
}
context
'with shared runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:shared
)
}
...
...
@@ -19,13 +19,11 @@ describe UpdateBuildMinutesService, services: true do
it
"creates a metrics and sets duration"
do
subject
# expect(project.reload.project_metrics.shared_runners_minutes).to(
# eq(build.duration)
# )
expect
(
project
.
project_metrics
.
reload
.
shared_runners_minutes
).
to
eq
(
build
.
duration
.
to_i
)
expect
(
namespace
.
reload
.
namespace_metrics
.
shared_runners_minutes
).
to
(
eq
(
build
.
duration
)
)
expect
(
namespace
.
namespace_metrics
.
reload
.
shared_runners_minutes
).
to
eq
(
build
.
duration
.
to_i
)
end
context
'when metrics are created'
do
...
...
@@ -37,13 +35,11 @@ describe UpdateBuildMinutesService, services: true do
it
"updates metrics and adds duration"
do
subject
expect
(
project
.
project_metrics
.
shared_runners_minutes
).
to
(
eq
(
100
+
build
.
duration
)
)
expect
(
project
.
project_metrics
.
reload
.
shared_runners_minutes
).
to
eq
(
100
+
build
.
duration
.
to_i
)
expect
(
namespace
.
namespace_metrics
.
shared_runners_minutes
).
to
(
eq
(
100
+
build
.
duration
)
)
expect
(
namespace
.
namespace_metrics
.
reload
.
shared_runners_minutes
).
to
eq
(
100
+
build
.
duration
.
to_i
)
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