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
fd716d44
Commit
fd716d44
authored
Sep 28, 2021
by
Fabio Pitino
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make build_id param as required when updating CI minutes async
Changelog: other EE: true
parent
2b719bdf
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
10 additions
and
52 deletions
+10
-52
ee/app/workers/ci/minutes/update_project_and_namespace_usage_worker.rb
...s/ci/minutes/update_project_and_namespace_usage_worker.rb
+1
-1
ee/spec/workers/ci/minutes/update_project_and_namespace_usage_worker_spec.rb
...minutes/update_project_and_namespace_usage_worker_spec.rb
+9
-51
No files found.
ee/app/workers/ci/minutes/update_project_and_namespace_usage_worker.rb
View file @
fd716d44
...
...
@@ -9,7 +9,7 @@ module Ci
urgency
:low
data_consistency
:always
# primarily performs writes
def
perform
(
consumption
,
project_id
,
namespace_id
,
build_id
=
nil
)
def
perform
(
consumption
,
project_id
,
namespace_id
,
build_id
)
::
Ci
::
Minutes
::
UpdateProjectAndNamespaceUsageService
.
new
(
project_id
,
namespace_id
,
build_id
)
.
execute
(
consumption
)
...
...
ee/spec/workers/ci/minutes/update_project_and_namespace_usage_worker_spec.rb
View file @
fd716d44
...
...
@@ -11,8 +11,10 @@ RSpec.describe Ci::Minutes::UpdateProjectAndNamespaceUsageWorker do
let
(
:consumption_seconds
)
{
consumption
*
60
}
let
(
:worker
)
{
described_class
.
new
}
describe
'#perform'
do
shared_examples
'executes the update'
do
describe
'#perform'
,
:clean_gitlab_redis_shared_state
do
subject
{
perform_multiple
([
consumption
,
project
.
id
,
namespace
.
id
,
build
.
id
])
}
context
'behaves idempotently for monthly usage update'
do
it
'executes UpdateProjectAndNamespaceUsageService'
do
service_instance
=
double
expect
(
::
Ci
::
Minutes
::
UpdateProjectAndNamespaceUsageService
).
to
receive
(
:new
).
at_least
(
:once
).
and_return
(
service_instance
)
...
...
@@ -29,57 +31,13 @@ RSpec.describe Ci::Minutes::UpdateProjectAndNamespaceUsageWorker do
end
end
shared_examples
'skips the update'
do
it
'does not execute UpdateProjectAndNamespaceUsageService'
do
expect
(
::
Ci
::
Minutes
::
UpdateProjectAndNamespaceUsageService
).
not_to
receive
(
:new
)
subject
end
end
context
'when build_id is not passed as parameter (param backward compatibility)'
do
subject
{
worker
.
perform
(
consumption
,
project
.
id
,
namespace
.
id
)
}
it_behaves_like
'executes the update'
it
'updates legacy statistics'
do
subject
expect
(
project
.
statistics
.
reload
.
shared_runners_seconds
).
to
eq
(
consumption_seconds
)
expect
(
namespace
.
reload
.
namespace_statistics
.
shared_runners_seconds
).
to
eq
(
consumption_seconds
)
end
context
'does not behave idempotently'
do
subject
{
perform_multiple
([
consumption
,
project
.
id
,
namespace
.
id
],
worker:
worker
)
}
it
'does not behave idempotently for legacy statistics update'
do
expect
(
::
Ci
::
Minutes
::
UpdateProjectAndNamespaceUsageService
).
to
receive
(
:new
).
twice
.
and_call_original
it
'executes the operation multiple times'
do
expect
(
::
Ci
::
Minutes
::
UpdateProjectAndNamespaceUsageService
).
to
receive
(
:new
).
twice
.
and_call_original
subject
subject
expect
(
project
.
statistics
.
reload
.
shared_runners_seconds
).
to
eq
(
2
*
consumption_seconds
)
expect
(
namespace
.
reload
.
namespace_statistics
.
shared_runners_seconds
).
to
eq
(
2
*
consumption_seconds
)
expect
(
Ci
::
Minutes
::
NamespaceMonthlyUsage
.
find_by
(
namespace:
namespace
).
amount_used
).
to
eq
(
2
*
consumption
)
expect
(
Ci
::
Minutes
::
ProjectMonthlyUsage
.
find_by
(
project:
project
).
amount_used
).
to
eq
(
2
*
consumption
)
end
end
end
context
'when build_id is passed as parameter'
,
:clean_gitlab_redis_shared_state
do
subject
{
perform_multiple
([
consumption
,
project
.
id
,
namespace
.
id
,
build
.
id
])
}
context
'behaves idempotently for monthly usage update'
do
it_behaves_like
'executes the update'
end
it
'does not behave idempotently for legacy statistics update'
do
expect
(
::
Ci
::
Minutes
::
UpdateProjectAndNamespaceUsageService
).
to
receive
(
:new
).
twice
.
and_call_original
subject
expect
(
project
.
statistics
.
reload
.
shared_runners_seconds
).
to
eq
(
2
*
consumption_seconds
)
expect
(
namespace
.
reload
.
namespace_statistics
.
shared_runners_seconds
).
to
eq
(
2
*
consumption_seconds
)
end
expect
(
project
.
statistics
.
reload
.
shared_runners_seconds
).
to
eq
(
2
*
consumption_seconds
)
expect
(
namespace
.
reload
.
namespace_statistics
.
shared_runners_seconds
).
to
eq
(
2
*
consumption_seconds
)
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