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
08dc2c7c
Commit
08dc2c7c
authored
Jan 19, 2017
by
Kamil Trzcinski
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Rename shared_runners_minutes to be shared_runners_seconds when calculating data
parent
71165067
Changes
21
Hide whitespace changes
Inline
Side-by-side
Showing
21 changed files
with
68 additions
and
53 deletions
+68
-53
app/helpers/ee/groups_helper.rb
app/helpers/ee/groups_helper.rb
+2
-2
app/models/ee/namespace.rb
app/models/ee/namespace.rb
+1
-1
app/models/ee/project.rb
app/models/ee/project.rb
+1
-1
app/models/namespace_statistics.rb
app/models/namespace_statistics.rb
+4
-0
app/models/project_statistics.rb
app/models/project_statistics.rb
+4
-0
app/services/ee/ci/register_build_service.rb
app/services/ee/ci/register_build_service.rb
+1
-1
app/services/update_build_minutes_service.rb
app/services/update_build_minutes_service.rb
+3
-3
app/views/groups/pipeline_quota/index.html.haml
app/views/groups/pipeline_quota/index.html.haml
+1
-1
app/workers/clear_shared_runners_minutes_worker.rb
app/workers/clear_shared_runners_minutes_worker.rb
+4
-4
db/migrate/20170106172236_create_table_namespace_statistics.rb
...grate/20170106172236_create_table_namespace_statistics.rb
+2
-2
db/migrate/20170106172237_add_shared_runners_seconds_to_project_statistics.rb
...72237_add_shared_runners_seconds_to_project_statistics.rb
+3
-3
db/schema.rb
db/schema.rb
+4
-4
spec/factories/namespaces.rb
spec/factories/namespaces.rb
+3
-3
spec/lib/prependable_spec.rb
spec/lib/prependable_spec.rb
+1
-1
spec/models/ee/namespace_spec.rb
spec/models/ee/namespace_spec.rb
+2
-1
spec/models/ee/project_spec.rb
spec/models/ee/project_spec.rb
+2
-1
spec/models/namespace_statistics_spec.rb
spec/models/namespace_statistics_spec.rb
+6
-0
spec/models/project_spec.rb
spec/models/project_spec.rb
+3
-3
spec/services/ee/ci/register_build_service_spec.rb
spec/services/ee/ci/register_build_service_spec.rb
+3
-3
spec/services/update_build_minutes_service_spec.rb
spec/services/update_build_minutes_service_spec.rb
+12
-13
spec/workers/clear_shared_runners_minutes_worker_spec.rb
spec/workers/clear_shared_runners_minutes_worker_spec.rb
+6
-6
No files found.
app/helpers/ee/groups_helper.rb
View file @
08dc2c7c
module
EE
module
EE
module
GroupsHelper
module
GroupsHelper
def
group_shared_runner_limits_quota
(
group
)
def
group_shared_runner_limits_quota
(
group
)
used
=
group
.
shared_runners_minutes
used
=
group
.
shared_runners_minutes
.
to_i
if
group
.
shared_runners_minutes_limit_enabled?
if
group
.
shared_runners_minutes_limit_enabled?
limit
=
group
.
actual_shared_runners_minutes_limit
limit
=
group
.
actual_shared_runners_minutes_limit
...
@@ -19,7 +19,7 @@ module EE
...
@@ -19,7 +19,7 @@ module EE
def
group_shared_runner_limits_percent_used
(
group
)
def
group_shared_runner_limits_percent_used
(
group
)
return
0
unless
group
.
shared_runners_minutes_limit_enabled?
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
end
def
group_shared_runner_limits_progress_bar
(
group
)
def
group_shared_runner_limits_progress_bar
(
group
)
...
...
app/models/ee/namespace.rb
View file @
08dc2c7c
...
@@ -9,7 +9,7 @@ module EE
...
@@ -9,7 +9,7 @@ module EE
prepended
do
prepended
do
has_one
:namespace_statistics
,
dependent: :destroy
has_one
:namespace_statistics
,
dependent: :destroy
delegate
:shared_runners_minutes
,
:shared_runners_
minute
s_last_reset
,
delegate
:shared_runners_minutes
,
:shared_runners_
seconds
,
:shared_runners_second
s_last_reset
,
to: :namespace_statistics
,
allow_nil:
true
to: :namespace_statistics
,
allow_nil:
true
end
end
...
...
app/models/ee/project.rb
View file @
08dc2c7c
...
@@ -9,7 +9,7 @@ module EE
...
@@ -9,7 +9,7 @@ module EE
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_
minute
s_last_reset
,
delegate
:shared_runners_minutes
,
:shared_runners_
seconds
,
:shared_runners_second
s_last_reset
,
to: :statistics
,
allow_nil:
true
to: :statistics
,
allow_nil:
true
delegate
:actual_shared_runners_minutes_limit
,
delegate
:actual_shared_runners_minutes_limit
,
...
...
app/models/namespace_statistics.rb
View file @
08dc2c7c
...
@@ -2,4 +2,8 @@ class NamespaceStatistics < ActiveRecord::Base
...
@@ -2,4 +2,8 @@ class NamespaceStatistics < ActiveRecord::Base
belongs_to
:namespace
belongs_to
:namespace
validates
:namespace
,
presence:
true
validates
:namespace
,
presence:
true
def
shared_runners_minutes
shared_runners_seconds
.
to_i
/
60.0
end
end
end
app/models/project_statistics.rb
View file @
08dc2c7c
...
@@ -7,6 +7,10 @@ class ProjectStatistics < ActiveRecord::Base
...
@@ -7,6 +7,10 @@ class ProjectStatistics < ActiveRecord::Base
STORAGE_COLUMNS
=
[
:repository_size
,
:lfs_objects_size
,
:build_artifacts_size
]
STORAGE_COLUMNS
=
[
:repository_size
,
:lfs_objects_size
,
:build_artifacts_size
]
STATISTICS_COLUMNS
=
[
:commit_count
]
+
STORAGE_COLUMNS
STATISTICS_COLUMNS
=
[
:commit_count
]
+
STORAGE_COLUMNS
def
shared_runners_minutes
shared_runners_seconds
.
to_i
/
60.0
end
def
total_repository_size
def
total_repository_size
repository_size
+
lfs_objects_size
repository_size
+
lfs_objects_size
end
end
...
...
app/services/ee/ci/register_build_service.rb
View file @
08dc2c7c
...
@@ -21,7 +21,7 @@ module EE
...
@@ -21,7 +21,7 @@ module EE
where
(
'namespaces.id = projects.namespace_id'
).
where
(
'namespaces.id = projects.namespace_id'
).
joins
(
'LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id'
).
joins
(
'LEFT JOIN namespace_statistics ON namespace_statistics.namespace_id = namespaces.id'
).
where
(
'COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR '
\
where
(
'COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) = 0 OR '
\
'COALESCE(namespace_statistics.shared_runners_
minutes, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0)
'
,
'COALESCE(namespace_statistics.shared_runners_
seconds, 0) < COALESCE(namespaces.shared_runners_minutes_limit, ?, 0) * 60
'
,
application_shared_runners_minutes
,
application_shared_runners_minutes
).
application_shared_runners_minutes
,
application_shared_runners_minutes
).
select
(
'1'
)
select
(
'1'
)
end
end
...
...
app/services/update_build_minutes_service.rb
View file @
08dc2c7c
...
@@ -4,11 +4,11 @@ class UpdateBuildMinutesService < BaseService
...
@@ -4,11 +4,11 @@ class UpdateBuildMinutesService < BaseService
return
unless
build
.
complete?
return
unless
build
.
complete?
return
unless
build
.
duration
return
unless
build
.
duration
ProjectStatistics
.
update_counters
(
project
.
statistics
,
ProjectStatistics
.
update_counters
(
project
_
statistics
,
shared_runners_
minute
s:
build
.
duration
)
shared_runners_
second
s:
build
.
duration
)
NamespaceStatistics
.
update_counters
(
namespace_statistics
,
NamespaceStatistics
.
update_counters
(
namespace_statistics
,
shared_runners_
minute
s:
build
.
duration
)
shared_runners_
second
s:
build
.
duration
)
end
end
private
private
...
...
app/views/groups/pipeline_quota/index.html.haml
View file @
08dc2c7c
...
@@ -6,7 +6,7 @@
...
@@ -6,7 +6,7 @@
.row
.row
.col-sm-6
.col-sm-6
%strong
%strong
-
last_reset
=
@group
.
shared_runners_
minute
s_last_reset
-
last_reset
=
@group
.
shared_runners_
second
s_last_reset
-
if
last_reset
-
if
last_reset
Usage since
Usage since
=
last_reset
.
strftime
(
'%b %d, %Y'
)
=
last_reset
.
strftime
(
'%b %d, %Y'
)
...
...
app/workers/clear_shared_runners_minutes_worker.rb
View file @
08dc2c7c
...
@@ -8,12 +8,12 @@ class ClearSharedRunnersMinutesWorker
...
@@ -8,12 +8,12 @@ class ClearSharedRunnersMinutesWorker
return
unless
try_obtain_lease
return
unless
try_obtain_lease
ProjectStatistics
.
update_all
(
ProjectStatistics
.
update_all
(
shared_runners_
minute
s:
0
,
shared_runners_
second
s:
0
,
shared_runners_
minute
s_last_reset:
Time
.
now
)
shared_runners_
second
s_last_reset:
Time
.
now
)
NamespaceStatistics
.
update_all
(
NamespaceStatistics
.
update_all
(
shared_runners_
minute
s:
0
,
shared_runners_
second
s:
0
,
shared_runners_
minute
s_last_reset:
Time
.
now
)
shared_runners_
second
s_last_reset:
Time
.
now
)
end
end
private
private
...
...
db/migrate/20170106172236_create_table_namespace_statistics.rb
View file @
08dc2c7c
...
@@ -6,8 +6,8 @@ class CreateTableNamespaceStatistics < ActiveRecord::Migration
...
@@ -6,8 +6,8 @@ class CreateTableNamespaceStatistics < ActiveRecord::Migration
def
change
def
change
create_table
:namespace_statistics
do
|
t
|
create_table
:namespace_statistics
do
|
t
|
t
.
references
:namespace
,
null:
false
,
index:
{
unique:
true
},
foreign_key:
{
on_delete: :cascade
}
t
.
references
:namespace
,
null:
false
,
index:
{
unique:
true
},
foreign_key:
{
on_delete: :cascade
}
t
.
integer
:shared_runners_
minute
s
,
default:
0
,
null:
false
t
.
integer
:shared_runners_
second
s
,
default:
0
,
null:
false
t
.
timestamp
:shared_runners_
minute
s_last_reset
t
.
timestamp
:shared_runners_
second
s_last_reset
end
end
end
end
end
end
db/migrate/20170106172237_add_shared_runners_
minute
s_to_project_statistics.rb
→
db/migrate/20170106172237_add_shared_runners_
second
s_to_project_statistics.rb
View file @
08dc2c7c
class
AddSharedRunners
Minute
sToProjectStatistics
<
ActiveRecord
::
Migration
class
AddSharedRunners
Second
sToProjectStatistics
<
ActiveRecord
::
Migration
include
Gitlab
::
Database
::
MigrationHelpers
include
Gitlab
::
Database
::
MigrationHelpers
DOWNTIME
=
false
DOWNTIME
=
false
def
change
def
change
counter_column
=
{
limit:
8
,
null:
false
,
default:
0
}
counter_column
=
{
limit:
8
,
null:
false
,
default:
0
}
add_column
:project_statistics
,
:shared_runners_
minute
s
,
:integer
,
counter_column
add_column
:project_statistics
,
:shared_runners_
second
s
,
:integer
,
counter_column
add_column
:project_statistics
,
:shared_runners_
minute
s_last_reset
,
:timestamp
add_column
:project_statistics
,
:shared_runners_
second
s_last_reset
,
:timestamp
end
end
end
end
db/schema.rb
View file @
08dc2c7c
...
@@ -827,8 +827,8 @@ ActiveRecord::Schema.define(version: 20170106172237) do
...
@@ -827,8 +827,8 @@ ActiveRecord::Schema.define(version: 20170106172237) do
create_table
"namespace_statistics"
,
force: :cascade
do
|
t
|
create_table
"namespace_statistics"
,
force: :cascade
do
|
t
|
t
.
integer
"namespace_id"
,
null:
false
t
.
integer
"namespace_id"
,
null:
false
t
.
integer
"shared_runners_
minute
s"
,
default:
0
,
null:
false
t
.
integer
"shared_runners_
second
s"
,
default:
0
,
null:
false
t
.
datetime
"shared_runners_
minute
s_last_reset"
t
.
datetime
"shared_runners_
second
s_last_reset"
end
end
add_index
"namespace_statistics"
,
[
"namespace_id"
],
name:
"index_namespace_statistics_on_namespace_id"
,
unique:
true
,
using: :btree
add_index
"namespace_statistics"
,
[
"namespace_id"
],
name:
"index_namespace_statistics_on_namespace_id"
,
unique:
true
,
using: :btree
...
@@ -1050,8 +1050,8 @@ ActiveRecord::Schema.define(version: 20170106172237) do
...
@@ -1050,8 +1050,8 @@ ActiveRecord::Schema.define(version: 20170106172237) do
t
.
integer
"repository_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"repository_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"lfs_objects_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"lfs_objects_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"build_artifacts_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"build_artifacts_size"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"shared_runners_
minute
s"
,
limit:
8
,
default:
0
,
null:
false
t
.
integer
"shared_runners_
second
s"
,
limit:
8
,
default:
0
,
null:
false
t
.
datetime
"shared_runners_
minute
s_last_reset"
t
.
datetime
"shared_runners_
second
s_last_reset"
end
end
add_index
"project_statistics"
,
[
"namespace_id"
],
name:
"index_project_statistics_on_namespace_id"
,
using: :btree
add_index
"project_statistics"
,
[
"namespace_id"
],
name:
"index_project_statistics_on_namespace_id"
,
using: :btree
...
...
spec/factories/namespaces.rb
View file @
08dc2c7c
...
@@ -5,7 +5,7 @@ FactoryGirl.define do
...
@@ -5,7 +5,7 @@ FactoryGirl.define do
owner
owner
trait
:with_build_minutes
do
trait
:with_build_minutes
do
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
minutes:
400
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
seconds:
400
.
minutes
.
to_i
end
end
trait
:with_build_minutes_limit
do
trait
:with_build_minutes_limit
do
...
@@ -13,12 +13,12 @@ FactoryGirl.define do
...
@@ -13,12 +13,12 @@ FactoryGirl.define do
end
end
trait
:with_not_used_build_minutes_limit
do
trait
:with_not_used_build_minutes_limit
do
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
minutes:
300
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
seconds:
300
.
minutes
.
to_i
shared_runners_minutes_limit
500
shared_runners_minutes_limit
500
end
end
trait
:with_used_build_minutes_limit
do
trait
:with_used_build_minutes_limit
do
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
minutes:
1000
namespace_statistics
factory: :namespace_statistics
,
shared_runners_
seconds:
1000
.
minutes
.
to_i
shared_runners_minutes_limit
500
shared_runners_minutes_limit
500
end
end
end
end
...
...
spec/lib/prependable_spec.rb
View file @
08dc2c7c
...
@@ -9,7 +9,7 @@ describe Prependable do
...
@@ -9,7 +9,7 @@ describe Prependable do
end
end
it
'can execute a method'
do
it
'can execute a method'
do
expect
(
subject
.
class_value
).
to
eq
(
20
0
)
expect
(
subject
.
class_value
).
to
eq
(
20
)
end
end
end
end
...
...
spec/models/ee/namespace_spec.rb
View file @
08dc2c7c
...
@@ -6,7 +6,8 @@ describe Namespace, models: true do
...
@@ -6,7 +6,8 @@ describe Namespace, models: true do
it
{
is_expected
.
to
have_one
(
:namespace_statistics
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
have_one
(
:namespace_statistics
).
dependent
(
:destroy
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:namespace_statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:namespace_statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_last_reset
).
to
(
:namespace_statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds
).
to
(
:namespace_statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_seconds_last_reset
).
to
(
:namespace_statistics
)
}
describe
'#shared_runners_enabled?'
do
describe
'#shared_runners_enabled?'
do
subject
{
namespace
.
shared_runners_enabled?
}
subject
{
namespace
.
shared_runners_enabled?
}
...
...
spec/models/ee/project_spec.rb
View file @
08dc2c7c
...
@@ -3,7 +3,8 @@ require 'spec_helper'
...
@@ -3,7 +3,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
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes
).
to
(
:statistics
)
}
it
{
is_expected
.
to
delegate_method
(
:shared_runners_minutes_last_reset
).
to
(
:statistics
)
}
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
(
: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
)
}
...
...
spec/models/namespace_statistics_spec.rb
View file @
08dc2c7c
...
@@ -4,4 +4,10 @@ describe NamespaceStatistics, models: true do
...
@@ -4,4 +4,10 @@ describe NamespaceStatistics, models: true do
it
{
is_expected
.
to
belong_to
(
:namespace
)
}
it
{
is_expected
.
to
belong_to
(
:namespace
)
}
it
{
is_expected
.
to
validate_presence_of
(
:namespace
)
}
it
{
is_expected
.
to
validate_presence_of
(
:namespace
)
}
describe
'#shared_runners_minutes'
do
let
(
:namespace_statistics
)
{
build
(
:namespace_statistics
,
shared_runners_seconds:
120
)
}
it
{
expect
(
namespace_statistics
.
shared_runners_minutes
).
to
eq
(
2
)
}
end
end
end
spec/models/project_spec.rb
View file @
08dc2c7c
...
@@ -990,8 +990,8 @@ describe Project, models: true do
...
@@ -990,8 +990,8 @@ describe Project, models: true do
context
'when shared runners are disabled for project'
do
context
'when shared runners are disabled for project'
do
let!
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
false
)
}
let!
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
false
)
}
it
"returns a
project
"
do
it
"returns a
n empty array
"
do
is_expected
.
to
eq
([
project
])
is_expected
.
to
be_empty
end
end
end
end
end
end
...
@@ -1155,7 +1155,7 @@ describe Project, models: true do
...
@@ -1155,7 +1155,7 @@ describe Project, models: true do
let!
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
false
)
}
let!
(
:project
)
{
create
(
:empty_project
,
shared_runners_enabled:
false
)
}
it
"returns a empty list"
do
it
"returns a empty list"
do
is_expected
.
to
be_
nil
is_expected
.
to
be_
empty
end
end
end
end
end
end
...
...
spec/services/ee/ci/register_build_service_spec.rb
View file @
08dc2c7c
...
@@ -11,7 +11,7 @@ module Ci
...
@@ -11,7 +11,7 @@ module Ci
context
'for project with shared runners when global minutes limit is set'
do
context
'for project with shared runners when global minutes limit is set'
do
before
do
before
do
project
.
update
(
shared_runners_enabled:
true
)
project
.
update
(
shared_runners_enabled:
true
)
stub_application_setting
(
shared_runners_minutes:
5
00
)
stub_application_setting
(
shared_runners_minutes:
1
00
)
end
end
context
'allow to pick builds'
do
context
'allow to pick builds'
do
...
@@ -23,7 +23,7 @@ module Ci
...
@@ -23,7 +23,7 @@ module Ci
context
'when over the global quota'
do
context
'when over the global quota'
do
before
do
before
do
project
.
namespace
.
create_namespace_statistics
(
project
.
namespace
.
create_namespace_statistics
(
shared_runners_
minutes:
600
)
shared_runners_
seconds:
6001
)
end
end
let
(
:build
)
{
execute
(
shared_runner
)
}
let
(
:build
)
{
execute
(
shared_runner
)
}
...
@@ -54,7 +54,7 @@ module Ci
...
@@ -54,7 +54,7 @@ module Ci
context
'when namespace quota is bigger than a global one'
do
context
'when namespace quota is bigger than a global one'
do
before
do
before
do
project
.
namespace
.
update
(
shared_runners_minutes_limit:
10
00
)
project
.
namespace
.
update
(
shared_runners_minutes_limit:
10
1
)
end
end
it
"does return the build"
do
it
"does return the build"
do
...
...
spec/services/update_build_minutes_service_spec.rb
View file @
08dc2c7c
...
@@ -2,9 +2,9 @@ require 'spec_helper'
...
@@ -2,9 +2,9 @@ require 'spec_helper'
describe
UpdateBuildMinutesService
,
services:
true
do
describe
UpdateBuildMinutesService
,
services:
true
do
context
'#perform'
do
context
'#perform'
do
let
(
:namespace
)
{
create
(
:namespace
)
}
let
(
:namespace
)
{
create
(
:namespace
,
shared_runners_minutes_limit:
100
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:project
)
{
create
(
:empty_project
,
namespace:
namespace
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
let
(
:build
)
do
let
(
:build
)
do
create
(
:ci_build
,
:success
,
create
(
:ci_build
,
:success
,
runner:
runner
,
pipeline:
pipeline
,
runner:
runner
,
pipeline:
pipeline
,
...
@@ -16,29 +16,29 @@ describe UpdateBuildMinutesService, services: true do
...
@@ -16,29 +16,29 @@ describe UpdateBuildMinutesService, services: true do
context
'with shared runner'
do
context
'with shared runner'
do
let
(
:runner
)
{
create
(
:ci_runner
,
:shared
)
}
let
(
:runner
)
{
create
(
:ci_runner
,
:shared
)
}
it
"creates a
metr
ics and sets duration"
do
it
"creates a
statist
ics and sets duration"
do
subject
subject
expect
(
project
.
statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
project
.
statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
build
.
duration
.
to_i
)
to
eq
(
build
.
duration
.
to_i
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
build
.
duration
.
to_i
)
to
eq
(
build
.
duration
.
to_i
)
end
end
context
'when
metr
ics are created'
do
context
'when
statist
ics are created'
do
before
do
before
do
project
.
create_statistics
(
shared_runners_minute
s:
100
)
project
.
statistics
.
update
(
shared_runners_second
s:
100
)
namespace
.
create_namespace_statistics
(
shared_runners_
minute
s:
100
)
namespace
.
create_namespace_statistics
(
shared_runners_
second
s:
100
)
end
end
it
"updates
metr
ics and adds duration"
do
it
"updates
statist
ics and adds duration"
do
subject
subject
expect
(
project
.
statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
project
.
statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
100
+
build
.
duration
.
to_i
)
to
eq
(
100
+
build
.
duration
.
to_i
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
minute
s
).
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_
second
s
).
to
eq
(
100
+
build
.
duration
.
to_i
)
to
eq
(
100
+
build
.
duration
.
to_i
)
end
end
end
end
...
@@ -47,10 +47,9 @@ describe UpdateBuildMinutesService, services: true do
...
@@ -47,10 +47,9 @@ describe UpdateBuildMinutesService, services: true do
context
'for specific runner'
do
context
'for specific runner'
do
let
(
:runner
)
{
create
(
:ci_runner
)
}
let
(
:runner
)
{
create
(
:ci_runner
)
}
it
"does not create
metr
ics"
do
it
"does not create
statist
ics"
do
subject
subject
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 @
08dc2c7c
...
@@ -16,35 +16,35 @@ describe ClearSharedRunnersMinutesWorker do
...
@@ -16,35 +16,35 @@ describe ClearSharedRunnersMinutesWorker do
let
(
:statistics
)
{
project
.
statistics
}
let
(
:statistics
)
{
project
.
statistics
}
before
do
before
do
statistics
.
update
(
shared_runners_
minute
s:
100
)
statistics
.
update
(
shared_runners_
second
s:
100
)
end
end
it
'clears counters'
do
it
'clears counters'
do
subject
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s
).
to
be_zero
expect
(
statistics
.
reload
.
shared_runners_
second
s
).
to
be_zero
end
end
it
'resets timer'
do
it
'resets timer'
do
subject
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s_last_reset
).
to
be_like_time
(
Time
.
now
)
expect
(
statistics
.
reload
.
shared_runners_
second
s_last_reset
).
to
be_like_time
(
Time
.
now
)
end
end
end
end
context
'when namespace statistics are defined'
do
context
'when namespace statistics are defined'
do
let!
(
:statistics
)
{
create
(
:namespace_statistics
,
shared_runners_
minute
s:
100
)
}
let!
(
:statistics
)
{
create
(
:namespace_statistics
,
shared_runners_
second
s:
100
)
}
it
'clears counters'
do
it
'clears counters'
do
subject
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s
).
to
be_zero
expect
(
statistics
.
reload
.
shared_runners_
second
s
).
to
be_zero
end
end
it
'resets timer'
do
it
'resets timer'
do
subject
subject
expect
(
statistics
.
reload
.
shared_runners_
minute
s_last_reset
).
to
be_like_time
(
Time
.
now
)
expect
(
statistics
.
reload
.
shared_runners_
second
s_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