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
0
Merge Requests
0
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
Léo-Paul Géneau
gitlab-ce
Commits
57129140
Commit
57129140
authored
Apr 26, 2018
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
backport changes from gitlab-org/gitlab-ee!5461
parent
55f07cc3
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
41 additions
and
31 deletions
+41
-31
spec/services/projects/housekeeping_service_spec.rb
spec/services/projects/housekeeping_service_spec.rb
+41
-31
No files found.
spec/services/projects/housekeeping_service_spec.rb
View file @
57129140
...
...
@@ -2,7 +2,7 @@ require 'spec_helper'
describe
Projects
::
HousekeepingService
do
subject
{
described_class
.
new
(
project
)
}
l
et
(
:project
)
{
create
(
:project
,
:repository
)
}
s
et
(
:project
)
{
create
(
:project
,
:repository
)
}
before
do
project
.
reset_pushes_since_gc
...
...
@@ -16,12 +16,12 @@ describe Projects::HousekeepingService do
it
'enqueues a sidekiq job'
do
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
:the_uuid
)
expect
(
subject
).
to
receive
(
:lease_key
).
and_return
(
:the_lease_key
)
expect
(
subject
).
to
receive
(
:task
).
and_return
(
:
the_tas
k
)
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:
the_task
,
:the_lease_key
,
:the_uuid
)
expect
(
subject
).
to
receive
(
:task
).
and_return
(
:
incremental_repac
k
)
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:
incremental_repack
,
:the_lease_key
,
:the_uuid
).
and_call_original
subject
.
execute
e
xpect
(
project
.
reload
.
pushes_since_gc
).
to
eq
(
0
)
Sidekiq
::
Testing
.
fake!
do
expect
{
subject
.
execute
}.
to
change
(
GitGarbageCollectWorker
.
jobs
,
:size
).
by
(
1
)
e
nd
end
it
'yields the block if given'
do
...
...
@@ -30,6 +30,16 @@ describe Projects::HousekeepingService do
end
.
to
yield_with_no_args
end
it
'resets counter after execution'
do
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
:the_uuid
)
allow
(
subject
).
to
receive
(
:gc_period
).
and_return
(
1
)
project
.
increment_pushes_since_gc
Sidekiq
::
Testing
.
inline!
do
expect
{
subject
.
execute
}.
to
change
{
project
.
pushes_since_gc
}.
to
(
0
)
end
end
context
'when no lease can be obtained'
do
before
do
expect
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
false
)
...
...
@@ -54,6 +64,30 @@ describe Projects::HousekeepingService do
end
.
not_to
yield_with_no_args
end
end
context
'task type'
do
it
'goes through all three housekeeping tasks, executing only the highest task when there is overlap'
do
allow
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
:the_uuid
)
allow
(
subject
).
to
receive
(
:lease_key
).
and_return
(
:the_lease_key
)
# At push 200
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:gc
,
:the_lease_key
,
:the_uuid
)
.
exactly
(
1
).
times
# At push 50, 100, 150
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:full_repack
,
:the_lease_key
,
:the_uuid
)
.
exactly
(
3
).
times
# At push 10, 20, ... (except those above)
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:incremental_repack
,
:the_lease_key
,
:the_uuid
)
.
exactly
(
16
).
times
201
.
times
do
subject
.
increment!
subject
.
execute
if
subject
.
needed?
end
expect
(
project
.
pushes_since_gc
).
to
eq
(
1
)
end
end
end
describe
'#needed?'
do
...
...
@@ -69,31 +103,7 @@ describe Projects::HousekeepingService do
describe
'#increment!'
do
it
'increments the pushes_since_gc counter'
do
expect
do
subject
.
increment!
end
.
to
change
{
project
.
pushes_since_gc
}.
from
(
0
).
to
(
1
)
expect
{
subject
.
increment!
}.
to
change
{
project
.
pushes_since_gc
}.
by
(
1
)
end
end
it
'goes through all three housekeeping tasks, executing only the highest task when there is overlap'
do
allow
(
subject
).
to
receive
(
:try_obtain_lease
).
and_return
(
:the_uuid
)
allow
(
subject
).
to
receive
(
:lease_key
).
and_return
(
:the_lease_key
)
# At push 200
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:gc
,
:the_lease_key
,
:the_uuid
)
.
exactly
(
1
).
times
# At push 50, 100, 150
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:full_repack
,
:the_lease_key
,
:the_uuid
)
.
exactly
(
3
).
times
# At push 10, 20, ... (except those above)
expect
(
GitGarbageCollectWorker
).
to
receive
(
:perform_async
).
with
(
project
.
id
,
:incremental_repack
,
:the_lease_key
,
:the_uuid
)
.
exactly
(
16
).
times
201
.
times
do
subject
.
increment!
subject
.
execute
if
subject
.
needed?
end
expect
(
project
.
pushes_since_gc
).
to
eq
(
1
)
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