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
b702b42a
Commit
b702b42a
authored
Mar 06, 2017
by
Douglas Barbosa Alexandre
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add tests for Geo::RepositoryBackfillService
parent
6789e4fc
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
85 additions
and
20 deletions
+85
-20
app/services/geo/repository_backfill_service.rb
app/services/geo/repository_backfill_service.rb
+31
-17
spec/services/geo/repository_backfill_service_spec.rb
spec/services/geo/repository_backfill_service_spec.rb
+54
-3
No files found.
app/services/geo/repository_backfill_service.rb
View file @
b702b42a
...
...
@@ -15,11 +15,7 @@ module Geo
log
(
'Started repository sync'
)
fetch_repositories
do
|
started_at
,
finished_at
|
log
(
'Tracking sync information'
)
registry
=
Geo
::
ProjectRegistry
.
find_or_create_by
(
project_id:
project
.
id
)
registry
.
last_repository_synced_at
=
started_at
registry
.
last_repository_successful_sync_at
=
finished_at
if
finished_at
registry
.
save
update_tracking_database
(
started_at
,
finished_at
)
end
log
(
'Finished repository sync'
)
...
...
@@ -41,18 +37,9 @@ module Geo
finished_at
=
nil
begin
project
.
create_repository
unless
project
.
repository_exists?
log
(
'Fetching repository'
)
project
.
repository
.
fetch_geo_mirror
(
ssh_url_to_repo
)
# Second .wiki call returns a Gollum::Wiki, and it will always create the physical repository when not found
if
project
.
wiki
.
wiki
.
exist?
log
(
'Fetching wiki repository'
)
project
.
wiki
.
repository
.
fetch_geo_mirror
(
ssh_url_to_wiki
)
end
log
(
'Expiring caches'
)
project
.
repository
.
after_sync
fetch_project_repository
fetch_wiki_repository
expire_repository_caches
finished_at
=
DateTime
.
now
rescue
Gitlab
::
Shell
::
Error
=>
e
...
...
@@ -62,6 +49,25 @@ module Geo
yield
started_at
,
finished_at
end
def
fetch_project_repository
log
(
'Fetching project repository'
)
project
.
create_repository
unless
project
.
repository_exists?
project
.
repository
.
fetch_geo_mirror
(
ssh_url_to_repo
)
end
def
fetch_wiki_repository
# Second .wiki call returns a Gollum::Wiki, and it will always create the physical repository when not found
if
project
.
wiki
.
wiki
.
exist?
log
(
'Fetching wiki repository'
)
project
.
wiki
.
repository
.
fetch_geo_mirror
(
ssh_url_to_wiki
)
end
end
def
expire_repository_caches
log
(
'Expiring caches'
)
project
.
repository
.
after_sync
end
def
try_obtain_lease
log
(
'Trying to obtain lease to sync repository'
)
...
...
@@ -78,6 +84,14 @@ module Geo
Gitlab
::
ExclusiveLease
.
cancel
(
lease_key
,
repository_lease
)
end
def
update_tracking_database
(
started_at
,
finished_at
)
log
(
'Tracking sync information'
)
registry
=
Geo
::
ProjectRegistry
.
find_or_create_by
(
project_id:
project
.
id
)
registry
.
last_repository_synced_at
=
started_at
registry
.
last_repository_successful_sync_at
=
finished_at
if
finished_at
registry
.
save
end
def
lease_key
@key
||=
"
#{
LEASE_KEY_PREFIX
}
:
#{
project
.
id
}
"
end
...
...
spec/services/geo/repository_backfill_service_spec.rb
View file @
b702b42a
require
'spec_helper'
describe
Geo
::
RepositoryBackfillService
,
services:
true
do
let
(
:project
)
{
create
(
:project
)
}
let!
(
:primary
)
{
create
(
:geo_node
,
:primary
,
host:
'primary-geo-node'
)
}
let
(
:project
)
{
create
(
:empty_project
)
}
subject
{
Geo
::
RepositoryBackfillService
.
new
(
project
)
}
subject
{
described_class
.
new
(
project
.
id
,
'123456'
)
}
describe
'#execute'
do
pending
{
raise
'must be implemented'
}
it
'fetches project repositories'
do
fetch_count
=
0
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
do
fetch_count
+=
1
end
subject
.
execute
expect
(
fetch_count
).
to
eq
2
end
it
'expires repository caches'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
{
true
}
expect_any_instance_of
(
Repository
).
to
receive
(
:after_sync
).
once
subject
.
execute
end
it
'releases leases'
do
expect
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:cancel
).
exactly
(
2
).
and_call_original
subject
.
execute
end
context
'tracking database'
do
it
'tracks repository sync'
do
expect
{
subject
.
execute
}.
to
change
(
Geo
::
ProjectRegistry
,
:count
).
by
(
1
)
end
it
'stores last_repository_successful_sync_at when succeed'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
{
true
}
subject
.
execute
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
expect
(
registry
.
last_repository_successful_sync_at
).
not_to
be_nil
end
it
'reset last_repository_successful_sync_at when fail'
do
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
{
raise
Gitlab
::
Shell
::
Error
}
subject
.
execute
registry
=
Geo
::
ProjectRegistry
.
find_by
(
project_id:
project
.
id
)
expect
(
registry
.
last_repository_successful_sync_at
).
to
be_nil
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