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
71e8307d
Commit
71e8307d
authored
Oct 04, 2021
by
Fabio Pitino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Remove direct setup of `shared_runners_seconds` in specs
parent
59451ea1
Changes
12
Hide whitespace changes
Inline
Side-by-side
Showing
12 changed files
with
64 additions
and
51 deletions
+64
-51
ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
+4
-2
ee/spec/features/profiles/usage_quotas_spec.rb
ee/spec/features/profiles/usage_quotas_spec.rb
+3
-1
ee/spec/models/ci/minutes/notification_spec.rb
ee/spec/models/ci/minutes/notification_spec.rb
+3
-1
ee/spec/presenters/ci/minutes/quota_presenter_spec.rb
ee/spec/presenters/ci/minutes/quota_presenter_spec.rb
+12
-10
ee/spec/requests/api/ci/runner/jobs_put_spec.rb
ee/spec/requests/api/ci/runner/jobs_put_spec.rb
+2
-11
ee/spec/requests/api/ci/runner/jobs_trace_spec.rb
ee/spec/requests/api/ci/runner/jobs_trace_spec.rb
+2
-11
ee/spec/services/ci/minutes/batch_reset_service_spec.rb
ee/spec/services/ci/minutes/batch_reset_service_spec.rb
+3
-1
ee/spec/services/ci/minutes/email_notification_service_spec.rb
...ec/services/ci/minutes/email_notification_service_spec.rb
+4
-4
ee/spec/services/ci/minutes/update_build_minutes_service_spec.rb
.../services/ci/minutes/update_build_minutes_service_spec.rb
+4
-2
ee/spec/services/ci/minutes/update_project_and_namespace_usage_service_spec.rb
...inutes/update_project_and_namespace_usage_service_spec.rb
+4
-2
ee/spec/services/ci/register_job_service_spec.rb
ee/spec/services/ci/register_job_service_spec.rb
+5
-6
ee/spec/support/ci/minutes_helpers.rb
ee/spec/support/ci/minutes_helpers.rb
+18
-0
No files found.
ee/spec/features/admin/admin_reset_pipeline_minutes_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
'Reset namespace pipeline minutes'
,
:js
do
include
::
Ci
::
MinutesHelpers
let
(
:admin
)
{
create
(
:admin
)
}
before
do
...
...
@@ -13,7 +15,7 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do
shared_examples
'resetting pipeline minutes'
do
context
'when namespace has namespace statistics'
do
before
do
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
100
)
set_ci_minutes_used
(
namespace
,
100
)
end
it
'resets pipeline minutes'
do
...
...
@@ -26,7 +28,7 @@ RSpec.describe 'Reset namespace pipeline minutes', :js do
expect
(
page
).
to
have_selector
(
'.gl-toast'
)
expect
(
current_path
).
to
include
(
namespace
.
path
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_seconds
).
to
eq
(
0
)
expect
(
namespace
.
reload
.
ci_minutes_quota
.
total_minutes_used
).
to
eq
(
0
)
expect
(
namespace
.
namespace_statistics
.
reload
.
shared_runners_seconds_last_reset
).
to
be_like_time
(
time
)
end
end
...
...
ee/spec/features/profiles/usage_quotas_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
'Profile > Usage Quota'
do
include
::
Ci
::
MinutesHelpers
using
RSpec
::
Parameterized
::
TableSyntax
let_it_be
(
:user
,
reload:
true
)
{
create
(
:user
)
}
...
...
@@ -36,7 +38,7 @@ RSpec.describe 'Profile > Usage Quota' do
before
do
project
.
update!
(
shared_runners_enabled:
shared_runners_enabled
)
s
tatistics
.
update!
(
shared_runners_seconds:
used
.
minutes
.
to_i
)
s
et_ci_minutes_used
(
namespace
,
used
)
namespace
.
update!
(
shared_runners_minutes_limit:
quota
)
visit
profile_usage_quotas_path
...
...
ee/spec/models/ci/minutes/notification_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
Minutes
::
Notification
do
include
::
Ci
::
MinutesHelpers
let_it_be
(
:user
)
{
create
(
:user
)
}
let
(
:shared_runners_enabled
)
{
true
}
let!
(
:project
)
{
create
(
:project
,
:repository
,
namespace:
group
,
shared_runners_enabled:
shared_runners_enabled
)
}
...
...
@@ -162,7 +164,7 @@ RSpec.describe Ci::Minutes::Notification do
shared_examples
'not eligible to see notifications'
do
before
do
group
.
shared_runners_minutes_limit
=
10
allow
(
group
).
to
receive
(
:shared_runners_seconds
).
and_return
(
8
.
minutes
)
set_ci_minutes_used
(
group
,
8
)
end
context
'when not permitted to see notifications'
do
...
...
ee/spec/presenters/ci/minutes/quota_presenter_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
Minutes
::
QuotaPresenter
do
include
::
Ci
::
MinutesHelpers
using
RSpec
::
Parameterized
::
TableSyntax
let_it_be_with_reload
(
:namespace
)
do
...
...
@@ -48,7 +50,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when minutes are used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
20
.
minutes
set_ci_minutes_used
(
namespace
,
20
)
end
it
'returns unlimited report with usage'
do
...
...
@@ -71,7 +73,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when minutes are not all used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
30
.
minutes
set_ci_minutes_used
(
namespace
,
30
)
end
it
'returns report with under quota'
do
...
...
@@ -85,7 +87,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when minutes are all used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
101
.
minutes
set_ci_minutes_used
(
namespace
,
101
)
end
it
'returns report with over quota'
do
...
...
@@ -113,7 +115,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when all monthly minutes are used and some puarchased minutes are used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
250
.
minutes
set_ci_minutes_used
(
namespace
,
250
)
end
it
'returns report with under quota'
do
...
...
@@ -127,7 +129,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when all monthly and all puarchased minutes have been used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
301
.
minutes
set_ci_minutes_used
(
namespace
,
301
)
end
it
'returns report with over quota'
do
...
...
@@ -141,7 +143,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when not all monthly minutes have been used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
190
.
minutes
set_ci_minutes_used
(
namespace
,
190
)
end
it
'returns report with no usage'
do
...
...
@@ -161,7 +163,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when all monthly minutes have been used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
201
.
minutes
set_ci_minutes_used
(
namespace
,
201
)
end
it
'returns report without usage'
do
...
...
@@ -175,7 +177,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
context
'when not all monthly minutes have been used'
do
before
do
namespace
.
namespace_statistics
.
shared_runners_seconds
=
190
.
minutes
set_ci_minutes_used
(
namespace
,
190
)
end
it
'returns report with no usage'
do
...
...
@@ -212,7 +214,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
allow
(
namespace
).
to
receive
(
:any_project_with_shared_runners_enabled?
).
and_return
(
true
)
namespace
.
shared_runners_minutes_limit
=
monthly_limit
namespace
.
extra_shared_runners_minutes_limit
=
purchased_limit
namespace
.
namespace_statistics
.
shared_runners_seconds
=
minutes_used
.
minutes
set_ci_minutes_used
(
namespace
,
minutes_used
)
end
it
'returns the percentage'
do
...
...
@@ -242,7 +244,7 @@ RSpec.describe Ci::Minutes::QuotaPresenter do
allow
(
quota
).
to
receive
(
:enabled?
).
and_return
(
limit_enabled
)
namespace
.
shared_runners_minutes_limit
=
monthly_limit
namespace
.
extra_shared_runners_minutes_limit
=
purchased_limit
namespace
.
namespace_statistics
.
shared_runners_seconds
=
minutes_used
.
minutes
set_ci_minutes_used
(
namespace
,
minutes_used
)
end
it
'returns the percentage'
do
...
...
ee/spec/requests/api/ci/runner/jobs_put_spec.rb
View file @
71e8307d
...
...
@@ -3,7 +3,8 @@
require
'spec_helper'
RSpec
.
describe
API
::
Ci
::
Runner
,
:clean_gitlab_redis_shared_state
do
let_it_be
(
:group
)
{
create
(
:group
,
shared_runners_minutes_limit:
100
)
}
let_it_be
(
:minutes_used
)
{
95
+
Ci
::
Minutes
::
TrackLiveConsumptionService
::
CONSUMPTION_THRESHOLD
.
abs
}
let_it_be
(
:group
)
{
create
(
:group
,
:with_ci_minutes
,
ci_minutes_limit:
100
,
ci_minutes_used:
minutes_used
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:private
,
namespace:
group
,
shared_runners_enabled:
true
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
ref:
'master'
)
}
let_it_be
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
...
...
@@ -24,16 +25,6 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
pipeline:
pipeline
)
end
let
(
:minutes_already_consumed
)
do
95
+
Ci
::
Minutes
::
TrackLiveConsumptionService
::
CONSUMPTION_THRESHOLD
.
abs
end
let!
(
:statistics
)
do
create
(
:namespace_statistics
,
namespace:
group
,
shared_runners_seconds:
minutes_already_consumed
.
minutes
)
end
it
'tracks CI minutes usage of running job'
do
expect
(
Ci
::
Minutes
::
TrackLiveConsumptionService
).
to
receive
(
:new
).
with
(
job
).
and_call_original
...
...
ee/spec/requests/api/ci/runner/jobs_trace_spec.rb
View file @
71e8307d
...
...
@@ -3,7 +3,8 @@
require
'spec_helper'
RSpec
.
describe
API
::
Ci
::
Runner
,
:clean_gitlab_redis_shared_state
do
let_it_be
(
:group
)
{
create
(
:group
,
shared_runners_minutes_limit:
100
)
}
let_it_be
(
:minutes_used
)
{
95
+
Ci
::
Minutes
::
TrackLiveConsumptionService
::
CONSUMPTION_THRESHOLD
.
abs
}
let_it_be
(
:group
)
{
create
(
:group
,
:with_ci_minutes
,
ci_minutes_limit:
100
,
ci_minutes_used:
minutes_used
)
}
let_it_be
(
:project
)
{
create
(
:project
,
:private
,
namespace:
group
,
shared_runners_enabled:
true
)
}
let_it_be
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
,
ref:
'master'
)
}
let_it_be
(
:runner
)
{
create
(
:ci_runner
,
:instance
)
}
...
...
@@ -24,16 +25,6 @@ RSpec.describe API::Ci::Runner, :clean_gitlab_redis_shared_state do
pipeline:
pipeline
)
end
let
(
:minutes_already_consumed
)
do
95
+
Ci
::
Minutes
::
TrackLiveConsumptionService
::
CONSUMPTION_THRESHOLD
.
abs
end
let!
(
:statistics
)
do
create
(
:namespace_statistics
,
namespace:
group
,
shared_runners_seconds:
minutes_already_consumed
.
minutes
)
end
it
'tracks CI minutes usage of running job'
do
expect
(
Ci
::
Minutes
::
TrackLiveConsumptionService
).
to
receive
(
:new
).
with
(
job
).
and_call_original
...
...
ee/spec/services/ci/minutes/batch_reset_service_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
Minutes
::
BatchResetService
do
include
::
Ci
::
MinutesHelpers
let
(
:service
)
{
described_class
.
new
}
describe
'#execute!'
do
...
...
@@ -18,7 +20,7 @@ RSpec.describe Ci::Minutes::BatchResetService do
last_ci_minutes_notification_at:
Time
.
current
,
last_ci_minutes_usage_notification_level:
30
)
create
(
:namespace_statistics
,
namespace:
namespace
,
shared_runners_seconds:
seconds_used
)
set_ci_minutes_used
(
namespace
,
seconds_used
.
to_f
/
60
)
create
(
:project
,
namespace:
namespace
).
tap
do
|
project
|
create
(
:project_statistics
,
...
...
ee/spec/services/ci/minutes/email_notification_service_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
Minutes
::
EmailNotificationService
do
include
::
Ci
::
MinutesHelpers
describe
'#execute'
do
using
RSpec
::
Parameterized
::
TableSyntax
...
...
@@ -88,11 +90,9 @@ RSpec.describe Ci::Minutes::EmailNotificationService do
Ci
::
Minutes
::
NamespaceMonthlyUsage
.
find_or_create_current
(
namespace_id:
namespace
.
id
)
end
let!
(
:namespace_statistics
)
do
create
(
:namespace_statistics
,
namespace:
namespace
,
shared_runners_seconds:
minutes_used
*
60
)
end
before
do
set_ci_minutes_used
(
namespace
,
minutes_used
)
namespace_usage
.
update_column
(
:notification_level
,
current_notification_level
)
namespace
.
update_column
(
:shared_runners_minutes_limit
,
monthly_minutes_limit
)
...
...
ee/spec/services/ci/minutes/update_build_minutes_service_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
Minutes
::
UpdateBuildMinutesService
do
include
::
Ci
::
MinutesHelpers
let
(
:namespace
)
{
create
(
:namespace
,
shared_runners_minutes_limit:
100
)
}
let
(
:project
)
{
create
(
:project
,
:private
,
namespace:
namespace
)
}
let
(
:pipeline
)
{
create
(
:ci_pipeline
,
project:
project
)
}
...
...
@@ -120,9 +122,9 @@ RSpec.describe Ci::Minutes::UpdateBuildMinutesService do
let
(
:usage_in_minutes
)
{
(
100
.
to_f
/
60
).
round
(
2
)
}
before
do
set_ci_minutes_used
(
namespace
,
usage_in_minutes
)
project
.
statistics
.
update!
(
shared_runners_seconds:
usage_in_seconds
)
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
usage_in_seconds
)
create
(
:ci_namespace_monthly_usage
,
namespace:
namespace
,
amount_used:
usage_in_minutes
)
create
(
:ci_project_monthly_usage
,
project:
project
,
amount_used:
usage_in_minutes
)
end
...
...
ee/spec/services/ci/minutes/update_project_and_namespace_usage_service_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
Minutes
::
UpdateProjectAndNamespaceUsageService
do
include
::
Ci
::
MinutesHelpers
let
(
:project
)
{
create
(
:project
,
:private
)
}
let
(
:namespace
)
{
project
.
namespace
}
let
(
:build
)
{
create
(
:ci_build
)
}
...
...
@@ -135,9 +137,9 @@ RSpec.describe Ci::Minutes::UpdateProjectAndNamespaceUsageService do
before
do
project
.
statistics
.
update!
(
shared_runners_seconds:
existing_usage_in_seconds
)
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
existing_usage_in_seconds
)
create
(
:ci_namespace_monthly_usage
,
namespace:
namespace
,
amount_used:
existing_usage_in_minutes
)
create
(
:ci_project_monthly_usage
,
project:
project
,
amount_used:
existing_usage_in_minutes
)
set_ci_minutes_used
(
namespace
,
existing_usage_in_minutes
)
end
it
'does not create nested transactions'
,
:delete
do
...
...
ee/spec/services/ci/register_job_service_spec.rb
View file @
71e8307d
...
...
@@ -3,6 +3,8 @@
require
'spec_helper'
RSpec
.
describe
Ci
::
RegisterJobService
,
'#execute'
do
include
::
Ci
::
MinutesHelpers
let_it_be_with_refind
(
:shared_runner
)
{
create
(
:ci_runner
,
:instance
)
}
let!
(
:project
)
{
create
(
:project
,
shared_runners_enabled:
true
)
}
...
...
@@ -15,8 +17,7 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
shared_examples
'returns a build'
do
|
runners_minutes_used
|
before
do
project
.
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
runners_minutes_used
*
60
)
set_ci_minutes_used
(
project
.
namespace
,
runners_minutes_used
)
end
context
'with traversal_ids enabled'
do
...
...
@@ -67,8 +68,7 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
shared_examples
'does not return a build'
do
|
runners_minutes_used
|
before
do
project
.
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
runners_minutes_used
*
60
)
set_ci_minutes_used
(
project
.
namespace
,
runners_minutes_used
)
pending_build
.
reload
pending_build
.
create_queuing_entry!
end
...
...
@@ -241,8 +241,7 @@ RSpec.describe Ci::RegisterJobService, '#execute' do
group
.
update_columns
(
shared_runners_minutes_limit:
20
)
root_ancestor
.
update!
(
shared_runners_minutes_limit:
10
)
root_ancestor
.
create_namespace_statistics
(
shared_runners_seconds:
60
*
11
)
set_ci_minutes_used
(
root_ancestor
,
11
)
end
it_behaves_like
'does not return a build'
,
11
...
...
ee/spec/support/ci/minutes_helpers.rb
0 → 100644
View file @
71e8307d
# frozen_string_literal: true
module
Ci
module
MinutesHelpers
# TODO: Remove with https://gitlab.com/gitlab-org/gitlab/-/issues/277452
def
set_ci_minutes_used
(
namespace
,
minutes
)
if
namespace
.
namespace_statistics
namespace
.
namespace_statistics
.
update!
(
shared_runners_seconds:
minutes
.
minutes
)
else
namespace
.
create_namespace_statistics
(
shared_runners_seconds:
minutes
.
minutes
)
end
::
Ci
::
Minutes
::
NamespaceMonthlyUsage
.
find_or_create_current
(
namespace_id:
namespace
.
id
)
.
update!
(
amount_used:
minutes
)
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