Commit a40a136e authored by Patrick Steinhardt's avatar Patrick Steinhardt

spec: Do not stub temporary repo in sync service shared examples

When synchronizing repositories, then depending on a retry counter we
may either fetch into the real repository, or recreate the repo by first
creating a temporary staging repository, populating that repository and
then moving it into place. Our tests stub out this logic though such
that we always end up fetching into the real repository: this both keeps
us from exercising whether we fetch into the expected repo, and this
logic will break when Gitaly changes semantics of the CreateRepository
RPC to raise an error if the repository exists already.

Fix this issue by not stubbing out the temporary repository. Instead, we
now assert that function calls end up using the correct repository.
parent 67082753
...@@ -102,16 +102,15 @@ end ...@@ -102,16 +102,15 @@ end
RSpec.shared_examples 'sync retries use the snapshot RPC' do RSpec.shared_examples 'sync retries use the snapshot RPC' do
context 'snapshot synchronization method' do context 'snapshot synchronization method' do
before do let(:temp_repo) { subject.send(:temp_repo) }
allow(subject).to receive(:temp_repo) { repository }
end
def receive_create_from_snapshot def receive_create_from_snapshot
receive(:create_from_snapshot).with(primary.snapshot_url(repository), match(/^GL-Geo/)) { Gitaly::CreateRepositoryFromSnapshotResponse.new } receive(:create_from_snapshot).with(primary.snapshot_url(temp_repo), match(/^GL-Geo/)) { Gitaly::CreateRepositoryFromSnapshotResponse.new }
end end
it 'does not attempt to snapshot for initial sync' do it 'does not attempt to snapshot for initial sync' do
expect(repository).not_to receive_create_from_snapshot expect(repository).not_to receive_create_from_snapshot
expect(temp_repo).not_to receive_create_from_snapshot
expect(subject).to receive(:fetch_geo_mirror).with(repository) expect(subject).to receive(:fetch_geo_mirror).with(repository)
subject.execute subject.execute
...@@ -121,6 +120,7 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do ...@@ -121,6 +120,7 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do
registry_with_retry_count(retry_count - 1) registry_with_retry_count(retry_count - 1)
expect(repository).not_to receive_create_from_snapshot expect(repository).not_to receive_create_from_snapshot
expect(temp_repo).not_to receive_create_from_snapshot
expect(subject).to receive(:fetch_geo_mirror).with(repository) expect(subject).to receive(:fetch_geo_mirror).with(repository)
subject.execute subject.execute
...@@ -130,16 +130,18 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do ...@@ -130,16 +130,18 @@ RSpec.shared_examples 'sync retries use the snapshot RPC' do
let!(:registry) { registry_with_retry_count(retry_count + 1) } let!(:registry) { registry_with_retry_count(retry_count + 1) }
it 'attempts to snapshot' do it 'attempts to snapshot' do
expect(repository).to receive_create_from_snapshot expect(repository).not_to receive_create_from_snapshot
expect(subject).not_to receive(:fetch_geo_mirror).with(repository) expect(temp_repo).to receive_create_from_snapshot
expect(subject).not_to receive(:fetch_geo_mirror).with(temp_repo)
expect(subject).to receive(:set_temp_repository_as_main) expect(subject).to receive(:set_temp_repository_as_main)
subject.execute subject.execute
end end
it 'attempts to fetch if snapshotting raises an exception' do it 'attempts to fetch if snapshotting raises an exception' do
expect(repository).to receive_create_from_snapshot.and_raise(ArgumentError) expect(repository).not_to receive_create_from_snapshot
expect(subject).to receive(:fetch_geo_mirror).with(repository) expect(temp_repo).to receive_create_from_snapshot.and_raise(ArgumentError)
expect(subject).to receive(:fetch_geo_mirror).with(temp_repo)
subject.execute subject.execute
end end
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment