Handle exceptions when syncing project repositories

parent e191eb67
...@@ -96,7 +96,7 @@ module Geo ...@@ -96,7 +96,7 @@ module Geo
project.wiki.repository.fetch_geo_mirror(ssh_url_to_wiki) project.wiki.repository.fetch_geo_mirror(ssh_url_to_wiki)
finished_at = DateTime.now finished_at = DateTime.now
rescue Gitlab::Shell::Error, ProjectWiki::CouldNotCreateWikiError => e rescue Gitlab::Git::Repository::NoRepository, Gitlab::Shell::Error, ProjectWiki::CouldNotCreateWikiError => e
Rails.logger.error("#{self.class.name}: Error syncing wiki repository for project #{project.path_with_namespace}: #{e}") Rails.logger.error("#{self.class.name}: Error syncing wiki repository for project #{project.path_with_namespace}: #{e}")
end end
......
...@@ -214,6 +214,22 @@ describe Geo::RepositorySyncService, services: true do ...@@ -214,6 +214,22 @@ describe Geo::RepositorySyncService, services: true do
subject.execute subject.execute
end end
context 'exceptions' do
it 'rescues when Gitlab::Shell::Error is raised' do
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror).with(/#{project.path_with_namespace}\.git/) { raise Gitlab::Shell::Error }
expect { subject.execute }.not_to raise_error
end
it 'rescues exception and fires after_create hook when Gitlab::Git::Repository::NoRepository is raised' do
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror).with(/#{project.path_with_namespace}\.git/) { raise Gitlab::Git::Repository::NoRepository }
expect_any_instance_of(Repository).to receive(:after_create)
expect { subject.execute }.not_to raise_error
end
end
context 'tracking database' do context 'tracking database' do
it 'updates last_repository_successful_sync_at' do it 'updates last_repository_successful_sync_at' do
subject.execute subject.execute
...@@ -266,6 +282,20 @@ describe Geo::RepositorySyncService, services: true do ...@@ -266,6 +282,20 @@ describe Geo::RepositorySyncService, services: true do
subject.execute subject.execute
end end
context 'exceptions' do
it 'rescues exception when Gitlab::Shell::Error is raised' do
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror).with(/#{project.path_with_namespace}\.wiki\.git/) { raise Gitlab::Shell::Error }
expect { subject.execute }.not_to raise_error
end
it 'rescues exception when Gitlab::Git::Repository::NoRepository is raised' do
allow_any_instance_of(Repository).to receive(:fetch_geo_mirror).with(/#{project.path_with_namespace}\.wiki\.git/) { raise Gitlab::Git::Repository::NoRepository }
expect { subject.execute }.not_to raise_error
end
end
context 'tracking database' do context 'tracking database' do
it 'updates last_wiki_successful_sync_at' do it 'updates last_wiki_successful_sync_at' do
subject.execute subject.execute
...@@ -294,26 +324,5 @@ describe Geo::RepositorySyncService, services: true do ...@@ -294,26 +324,5 @@ describe Geo::RepositorySyncService, services: true do
end end
end end
end end
context 'when Gitlab::Shell::Error is raised' do
let(:project) { create(:empty_project) }
it 'rescues exception' do
expect(subject).to receive(:fetch_project_repository).and_raise(Gitlab::Shell::Error)
expect { subject.execute }.not_to raise_error
end
end
context 'when Gitlab::Git::Repository::NoRepository is raised' do
let(:project) { create(:empty_project) }
it 'rescues exception and fires after_create hook' do
expect(subject).to receive(:fetch_project_repository).and_raise(Gitlab::Git::Repository::NoRepository)
expect_any_instance_of(Repository).to receive(:after_create)
expect { subject.execute }.not_to raise_error
end
end
end end
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