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
c1d5704f
Commit
c1d5704f
authored
Jan 19, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fix specs failures
parent
5071a971
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
82 additions
and
53 deletions
+82
-53
app/models/ee/application_setting.rb
app/models/ee/application_setting.rb
+1
-1
app/models/ee/namespace.rb
app/models/ee/namespace.rb
+1
-1
app/models/ee/project.rb
app/models/ee/project.rb
+2
-2
app/services/ee/ci/register_build_service.rb
app/services/ee/ci/register_build_service.rb
+1
-1
lib/active_support/prependable.rb
lib/active_support/prependable.rb
+0
-26
lib/prependable.rb
lib/prependable.rb
+24
-0
spec/models/ee/ci/build_spec.rb
spec/models/ee/ci/build_spec.rb
+3
-3
spec/models/ee/project_spec.rb
spec/models/ee/project_spec.rb
+30
-4
spec/services/ci/register_build_service_spec.rb
spec/services/ci/register_build_service_spec.rb
+2
-2
spec/services/update_build_minutes_service_spec.rb
spec/services/update_build_minutes_service_spec.rb
+5
-5
spec/workers/clear_shared_runners_minutes_worker_spec.rb
spec/workers/clear_shared_runners_minutes_worker_spec.rb
+13
-8
No files found.
app/models/ee/application_setting.rb
View file @
c1d5704f
...
@@ -4,7 +4,7 @@ module EE
...
@@ -4,7 +4,7 @@ module EE
# This module is intended to encapsulate EE-specific model logic
# This module is intended to encapsulate EE-specific model logic
# and be included in the `ApplicationSetting` model
# and be included in the `ApplicationSetting` model
module
ApplicationSetting
module
ApplicationSetting
extend
ActiveSupport
::
Prependable
extend
::
Prependable
prepended
do
prepended
do
validates
:shared_runners_minutes
,
validates
:shared_runners_minutes
,
...
...
app/models/ee/namespace.rb
View file @
c1d5704f
...
@@ -4,7 +4,7 @@ module EE
...
@@ -4,7 +4,7 @@ module EE
# This module is intended to encapsulate EE-specific model logic
# This module is intended to encapsulate EE-specific model logic
# and be included in the `Namespace` model
# and be included in the `Namespace` model
module
Namespace
module
Namespace
extend
ActiveSupport
::
Prependable
extend
::
Prependable
prepended
do
prepended
do
has_one
:namespace_statistics
,
dependent: :destroy
has_one
:namespace_statistics
,
dependent: :destroy
...
...
app/models/ee/project.rb
View file @
c1d5704f
...
@@ -4,13 +4,13 @@ module EE
...
@@ -4,13 +4,13 @@ module EE
# This module is intended to encapsulate EE-specific model logic
# This module is intended to encapsulate EE-specific model logic
# and be included in the `Project` model
# and be included in the `Project` model
module
Project
module
Project
extend
ActiveSupport
::
Prependable
extend
::
Prependable
prepended
do
prepended
do
scope
:with_shared_runners_limit_enabled
,
->
{
with_shared_runners
.
non_public_only
}
scope
:with_shared_runners_limit_enabled
,
->
{
with_shared_runners
.
non_public_only
}
delegate
:shared_runners_minutes
,
:shared_runners_minutes_last_reset
,
delegate
:shared_runners_minutes
,
:shared_runners_minutes_last_reset
,
to: :
project_
statistics
,
allow_nil:
true
to: :statistics
,
allow_nil:
true
delegate
:actual_shared_runners_minutes_limit
,
delegate
:actual_shared_runners_minutes_limit
,
:shared_runners_minutes_used?
,
to: :namespace
:shared_runners_minutes_used?
,
to: :namespace
...
...
app/services/ee/ci/register_build_service.rb
View file @
c1d5704f
...
@@ -5,7 +5,7 @@ module EE
...
@@ -5,7 +5,7 @@ module EE
# This module is intended to encapsulate EE-specific service logic
# This module is intended to encapsulate EE-specific service logic
# and be included in the `RegisterBuildService` service
# and be included in the `RegisterBuildService` service
module
RegisterBuildService
module
RegisterBuildService
extend
ActiveSupport
::
Prependable
extend
::
Prependable
def
builds_for_shared_runner
def
builds_for_shared_runner
return
super
unless
shared_runner_build_limits_feature_enabled?
return
super
unless
shared_runner_build_limits_feature_enabled?
...
...
lib/active_support/prependable.rb
deleted
100644 → 0
View file @
5071a971
# This module is based on: https://gist.github.com/bcardarella/5735987
module
ActiveSupport
module
Prependable
include
ActiveSupport
::
Concern
def
self
.
extended
(
base
)
#:nodoc:
base
.
instance_variable_set
(
:@_dependencies
,
[])
end
def
prepend_features
(
base
)
if
base
.
instance_variable_defined?
(
:@_dependencies
)
base
.
instance_variable_get
(
:@_dependencies
)
<<
self
return
false
else
return
false
if
base
<
self
super
base
.
singleton_class
.
send
(
:prepend
,
const_get
(
'ClassMethods'
))
if
const_defined?
(
:ClassMethods
)
@_dependencies
.
each
{
|
dep
|
base
.
send
(
:include
,
dep
)
}
base
.
class_eval
(
&
@_included_block
)
if
instance_variable_defined?
(
:@_included_block
)
end
end
alias_method
:prepended
,
:included
end
end
lib/prependable.rb
0 → 100644
View file @
c1d5704f
# This module is based on: https://gist.github.com/bcardarella/5735987
module
Prependable
include
ActiveSupport
::
Concern
def
self
.
extended
(
base
)
#:nodoc:
base
.
instance_variable_set
(
:@_dependencies
,
[])
end
def
prepend_features
(
base
)
if
base
.
instance_variable_defined?
(
:@_dependencies
)
base
.
instance_variable_get
(
:@_dependencies
)
<<
self
return
false
else
return
false
if
base
<
self
super
base
.
singleton_class
.
send
(
:prepend
,
const_get
(
'ClassMethods'
))
if
const_defined?
(
:ClassMethods
)
@_dependencies
.
each
{
|
dep
|
base
.
send
(
:include
,
dep
)
}
base
.
class_eval
(
&
@_included_block
)
if
instance_variable_defined?
(
:@_included_block
)
end
end
alias_method
:prepended
,
:included
end
spec/models/ee/ci/build_spec.rb
View file @
c1d5704f
...
@@ -12,8 +12,8 @@ describe Ci::Build, models: true do
...
@@ -12,8 +12,8 @@ describe Ci::Build, models: true do
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
let
(
:build
)
{
create
(
:ci_build
,
pipeline:
pipeline
)
}
describe
'#shared_runners_minutes_
quota
?'
do
describe
'#shared_runners_minutes_
limit_enabled
?'
do
subject
{
build
.
shared_runners_minutes_
quota
?
}
subject
{
build
.
shared_runners_minutes_
limit_enabled
?
}
context
'for shared runner'
do
context
'for shared runner'
do
before
do
before
do
...
@@ -21,7 +21,7 @@ describe Ci::Build, models: true do
...
@@ -21,7 +21,7 @@ describe Ci::Build, models: true do
end
end
it
do
it
do
expect
(
build
.
project
).
to
receive
(
:shared_runners_minutes_
quota
?
).
expect
(
build
.
project
).
to
receive
(
:shared_runners_minutes_
limit_enabled
?
).
and_return
(
true
)
and_return
(
true
)
is_expected
.
to
be_truthy
is_expected
.
to
be_truthy
...
...
spec/models/ee/project_spec.rb
View file @
c1d5704f
...
@@ -2,8 +2,8 @@ require 'spec_helper'
...
@@ -2,8 +2,8 @@ require 'spec_helper'
describe
Project
,
models:
true
do
describe
Project
,
models:
true
do
describe
'associations'
do
describe
'associations'
do
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:
project_
statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_last_reset
).
to
(
:
project_
statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_last_reset
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:actual_shared_runners_minutes_limit
).
to
(
:namespace
)
}
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_limit_enabled?
).
to
(
:namespace
)
}
...
@@ -45,10 +45,36 @@ describe Project, models: true do
...
@@ -45,10 +45,36 @@ describe Project, models: true do
end
end
end
end
describe
'#shared_runners_minutes_quota?'
do
describe
'#shared_runners_available?'
do
subject
{
project
.
shared_runners_available?
}
context
'with used build minutes'
do
let
(
:namespace
)
{
create
(
:namespace
,
:with_used_build_minutes_limit
)
}
let
(
:project
)
do
create
(
:empty_project
,
namespace:
namespace
,
shared_runners_enabled:
true
)
end
before
do
expect
(
namespace
).
to
receive
(
:shared_runners_minutes_used?
).
and_call_original
end
it
'shared runners are not available'
do
expect
(
project
.
shared_runners_available?
).
to
be_falsey
end
end
end
describe
'#shared_runners_minutes_limit_enabled?'
do
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
subject
{
project
.
shared_runners_minutes_quota?
}
subject
{
project
.
shared_runners_minutes_limit_enabled?
}
before
do
allow
(
project
.
namespace
).
to
receive
(
:shared_runners_minutes_limit_enabled?
).
and_return
(
true
)
end
context
'with shared runners enabled'
do
context
'with shared runners enabled'
do
before
do
before
do
...
...
spec/services/ci/register_build_service_spec.rb
View file @
c1d5704f
...
@@ -136,13 +136,13 @@ module Ci
...
@@ -136,13 +136,13 @@ module Ci
end
end
context
'shared runner'
do
context
'shared runner'
do
let
(
:build
)
{
service
.
execute
(
shared_runner
)
}
let
(
:build
)
{
execute
(
shared_runner
)
}
it
{
expect
(
build
).
to
be_nil
}
it
{
expect
(
build
).
to
be_nil
}
end
end
context
'specific runner'
do
context
'specific runner'
do
let
(
:build
)
{
service
.
execute
(
specific_runner
)
}
let
(
:build
)
{
execute
(
specific_runner
)
}
it
{
expect
(
build
).
to
be_kind_of
(
Build
)
}
it
{
expect
(
build
).
to
be_kind_of
(
Build
)
}
it
{
expect
(
build
).
to
be_valid
}
it
{
expect
(
build
).
to
be_valid
}
...
...
spec/services/update_build_minutes_service_spec.rb
View file @
c1d5704f
...
@@ -19,7 +19,7 @@ describe UpdateBuildMinutesService, services: true do
...
@@ -19,7 +19,7 @@ describe UpdateBuildMinutesService, services: true do
it
"creates a metrics and sets duration"
do
it
"creates a metrics and sets duration"
do
subject
subject
expect
(
project
.
project_
statistics
.
reload
.
shared_runners_minutes
).
expect
(
project
.
statistics
.
reload
.
shared_runners_minutes
).
to
eq
(
build
.
duration
.
to_i
)
to
eq
(
build
.
duration
.
to_i
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_minutes
).
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_minutes
).
...
@@ -28,14 +28,14 @@ describe UpdateBuildMinutesService, services: true do
...
@@ -28,14 +28,14 @@ describe UpdateBuildMinutesService, services: true do
context
'when metrics are created'
do
context
'when metrics are created'
do
before
do
before
do
project
.
create_
project_
statistics
(
shared_runners_minutes:
100
)
project
.
create_statistics
(
shared_runners_minutes:
100
)
namespace
.
create_namespace_
metr
ics
(
shared_runners_minutes:
100
)
namespace
.
create_namespace_
statist
ics
(
shared_runners_minutes:
100
)
end
end
it
"updates metrics and adds duration"
do
it
"updates metrics and adds duration"
do
subject
subject
expect
(
project
.
project_
statistics
.
reload
.
shared_runners_minutes
).
expect
(
project
.
statistics
.
reload
.
shared_runners_minutes
).
to
eq
(
100
+
build
.
duration
.
to_i
)
to
eq
(
100
+
build
.
duration
.
to_i
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_minutes
).
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_minutes
).
...
@@ -50,7 +50,7 @@ describe UpdateBuildMinutesService, services: true do
...
@@ -50,7 +50,7 @@ describe UpdateBuildMinutesService, services: true do
it
"does not create metrics"
do
it
"does not create metrics"
do
subject
subject
expect
(
project
.
project_
statistics
).
to
be_nil
expect
(
project
.
statistics
).
to
be_nil
expect
(
namespace
.
namespace_statistics
).
to
be_nil
expect
(
namespace
.
namespace_statistics
).
to
be_nil
end
end
end
end
...
...
spec/workers/clear_shared_runners_minutes_worker_spec.rb
View file @
c1d5704f
...
@@ -11,35 +11,40 @@ describe ClearSharedRunnersMinutesWorker do
...
@@ -11,35 +11,40 @@ describe ClearSharedRunnersMinutesWorker do
subject
{
worker
.
perform
}
subject
{
worker
.
perform
}
context
'when project metrics are defined'
do
context
'when project statistics are defined'
do
let!
(
:project_statistics
)
{
create
(
:project_statistics
,
shared_runners_minutes:
100
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
let
(
:statistics
)
{
project
.
statistics
}
before
do
statistics
.
update
(
shared_runners_minutes:
100
)
end
it
'clears counters'
do
it
'clears counters'
do
subject
subject
expect
(
project_
statistics
.
reload
.
shared_runners_minutes
).
to
be_zero
expect
(
statistics
.
reload
.
shared_runners_minutes
).
to
be_zero
end
end
it
'resets timer'
do
it
'resets timer'
do
subject
subject
expect
(
project_
statistics
.
reload
.
shared_runners_minutes_last_reset
).
to
be_like_time
(
Time
.
now
)
expect
(
statistics
.
reload
.
shared_runners_minutes_last_reset
).
to
be_like_time
(
Time
.
now
)
end
end
end
end
context
'when
project metr
ics are defined'
do
context
'when
namespace statist
ics are defined'
do
let!
(
:
namespace_
statistics
)
{
create
(
:namespace_statistics
,
shared_runners_minutes:
100
)
}
let!
(
:statistics
)
{
create
(
:namespace_statistics
,
shared_runners_minutes:
100
)
}
it
'clears counters'
do
it
'clears counters'
do
subject
subject
expect
(
namespace_
statistics
.
reload
.
shared_runners_minutes
).
to
be_zero
expect
(
statistics
.
reload
.
shared_runners_minutes
).
to
be_zero
end
end
it
'resets timer'
do
it
'resets timer'
do
subject
subject
expect
(
namespace_
statistics
.
reload
.
shared_runners_minutes_last_reset
).
to
be_like_time
(
Time
.
now
)
expect
(
statistics
.
reload
.
shared_runners_minutes_last_reset
).
to
be_like_time
(
Time
.
now
)
end
end
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