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
11aea03f
Commit
11aea03f
authored
Jul 15, 2017
by
Gabriel Mazetto
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Use shared examples to test base sync and dependent services
parent
a531a2d9
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
50 additions
and
42 deletions
+50
-42
spec/services/geo/base_sync_service_spec.rb
spec/services/geo/base_sync_service_spec.rb
+1
-26
spec/services/geo/repository_sync_service_spec.rb
spec/services/geo/repository_sync_service_spec.rb
+10
-8
spec/services/geo/wiki_sync_service_spec.rb
spec/services/geo/wiki_sync_service_spec.rb
+10
-8
spec/support/services/base_sync_service_shared_examples.rb
spec/support/services/base_sync_service_shared_examples.rb
+29
-0
No files found.
spec/services/geo/base_sync_service_spec.rb
View file @
11aea03f
...
...
@@ -4,31 +4,7 @@ describe Geo::BaseSyncService, services: true do
let
(
:project
)
{
build
(
'project'
)}
subject
{
described_class
.
new
(
project
)
}
describe
'#execute'
do
context
'when can acquire exclusive lease'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
12345
}
end
it
'executes the synchronization'
do
expect
(
subject
).
to
receive
(
:sync_repository
)
subject
.
execute
end
end
context
'when exclusive lease is not acquired'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
nil
}
end
it
'is does not execute synchronization'
do
expect
(
subject
).
not_to
receive
(
:sync_repository
)
subject
.
execute
end
end
end
it_behaves_like
'geo base sync execution'
describe
'#lease_key'
do
it
'returns a key in the correct pattern'
do
...
...
@@ -49,7 +25,6 @@ describe Geo::BaseSyncService, services: true do
end
it
'returns the prefix defined in the primary node'
do
expect
{
subject
.
send
(
:primary_ssh_path_prefix
)
}.
not_to
raise_error
expect
(
subject
.
send
(
:primary_ssh_path_prefix
)).
to
eq
(
'git@localhost:'
)
end
end
...
...
spec/services/geo/repository_sync_service_spec.rb
View file @
11aea03f
...
...
@@ -6,20 +6,22 @@ RSpec.describe Geo::RepositorySyncService, services: true do
subject
{
described_class
.
new
(
project
)
}
before
do
allow
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:new
)
.
with
(
subject
.
lease_key
,
anything
)
.
and_return
(
lease
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
.
and_return
(
true
)
end
it_behaves_like
'geo base sync execution'
describe
'#execute'
do
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:repository
)
{
project
.
repository
}
let
(
:url_to_repo
)
{
"
#{
primary
.
clone_url_prefix
}#{
project
.
path_with_namespace
}
.git"
}
before
do
allow
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:new
)
.
with
(
subject
.
lease_key
,
anything
)
.
and_return
(
lease
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
.
and_return
(
true
)
end
it
'fetches project repository'
do
expect
(
repository
).
to
receive
(
:fetch_geo_mirror
).
with
(
url_to_repo
).
once
...
...
spec/services/geo/wiki_sync_service_spec.rb
View file @
11aea03f
...
...
@@ -6,20 +6,22 @@ RSpec.describe Geo::WikiSyncService, services: true do
subject
{
described_class
.
new
(
project
)
}
before
do
allow
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:new
)
.
with
(
subject
.
lease_key
,
anything
)
.
and_return
(
lease
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
.
and_return
(
true
)
end
it_behaves_like
'geo base sync execution'
describe
'#execute'
do
let
(
:project
)
{
create
(
:project_empty_repo
)
}
let
(
:repository
)
{
project
.
wiki
.
repository
}
let
(
:url_to_repo
)
{
"
#{
primary
.
clone_url_prefix
}#{
project
.
path_with_namespace
}
.wiki.git"
}
before
do
allow
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:new
)
.
with
(
subject
.
lease_key
,
anything
)
.
and_return
(
lease
)
allow_any_instance_of
(
Repository
).
to
receive
(
:fetch_geo_mirror
)
.
and_return
(
true
)
end
it
'fetches wiki repository'
do
expect
(
repository
).
to
receive
(
:fetch_geo_mirror
).
with
(
url_to_repo
).
once
...
...
spec/support/services/base_sync_service_shared_examples.rb
0 → 100644
View file @
11aea03f
shared_examples
'geo base sync execution'
do
describe
'#execute'
do
let
(
:project
)
{
build
(
'project'
)}
context
'when can acquire exclusive lease'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
12345
}
end
it
'executes the synchronization'
do
expect
(
subject
).
to
receive
(
:sync_repository
)
subject
.
execute
end
end
context
'when exclusive lease is not acquired'
do
before
do
allow_any_instance_of
(
Gitlab
::
ExclusiveLease
).
to
receive
(
:try_obtain
)
{
nil
}
end
it
'is does not execute synchronization'
do
expect
(
subject
).
not_to
receive
(
:sync_repository
)
subject
.
execute
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