Rename repository verification service on secondary node

parent 8f105380
module Geo module Geo
class RepositoryVerifySecondaryService class RepositoryVerificationSecondaryService
include Gitlab::Geo::ProjectLogHelpers include Gitlab::Geo::ProjectLogHelpers
def initialize(registry, type) def initialize(registry, type)
......
...@@ -17,7 +17,7 @@ module Geo ...@@ -17,7 +17,7 @@ module Geo
def perform(registry_id) def perform(registry_id)
return unless Gitlab::Geo.secondary? return unless Gitlab::Geo.secondary?
@registry = Geo::ProjectRegistry.find_by_id(registry_id) @registry = Geo::ProjectRegistry.find_by(id: registry_id)
return if registry.nil? || project.nil? || project.pending_delete? return if registry.nil? || project.nil? || project.pending_delete?
try_obtain_lease do try_obtain_lease do
...@@ -29,7 +29,7 @@ module Geo ...@@ -29,7 +29,7 @@ module Geo
private private
def verify_checksum(type) def verify_checksum(type)
Geo::RepositoryVerifySecondaryService.new(registry, type).execute Geo::RepositoryVerificationSecondaryService.new(registry, type).execute
rescue => e rescue => e
log_error('Error verifying the repository checksum', e, type: type) log_error('Error verifying the repository checksum', e, type: type)
raise e raise e
......
require 'spec_helper' require 'spec_helper'
describe Geo::RepositoryVerifySecondaryService, :geo do describe Geo::RepositoryVerificationSecondaryService, :geo do
include ::EE::GeoHelpers include ::EE::GeoHelpers
let(:secondary) { create(:geo_node) } let(:secondary) { create(:geo_node) }
......
...@@ -10,24 +10,33 @@ describe Geo::RepositoryVerification::Secondary::SingleWorker, :postgresql, :cle ...@@ -10,24 +10,33 @@ describe Geo::RepositoryVerification::Secondary::SingleWorker, :postgresql, :cle
before do before do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
stub_exclusive_lease
end end
describe '#perform' do describe '#perform' do
it 'does not calculate the checksum when not running on a secondary' do it 'does not calculate the checksum when not running on a secondary' do
allow(Gitlab::Geo).to receive(:secondary?) { false } allow(Gitlab::Geo).to receive(:secondary?) { false }
expect_any_instance_of(Geo::RepositoryVerifySecondaryService).not_to receive(:execute)
subject.perform(registry.id) subject.perform(registry.id)
expect(registry.reload).to have_attributes(
repository_verification_checksum_sha: nil,
last_repository_verification_failure: nil,
wiki_verification_checksum_sha: nil,
last_wiki_verification_failure: nil
)
end end
it 'does not calculate the checksum when project is pending deletion' do it 'does not calculate the checksum when project is pending deletion' do
registry.project.update!(pending_delete: true) registry.project.update!(pending_delete: true)
expect_any_instance_of(Geo::RepositoryVerifySecondaryService).not_to receive(:execute)
subject.perform(registry.id) subject.perform(registry.id)
expect(registry.reload).to have_attributes(
repository_verification_checksum_sha: nil,
last_repository_verification_failure: nil,
wiki_verification_checksum_sha: nil,
last_wiki_verification_failure: nil
)
end end
it 'does not raise an error when registry could not be found' do it 'does not raise an error when registry could not be found' do
...@@ -41,12 +50,24 @@ describe Geo::RepositoryVerification::Secondary::SingleWorker, :postgresql, :cle ...@@ -41,12 +50,24 @@ describe Geo::RepositoryVerification::Secondary::SingleWorker, :postgresql, :cle
end end
it 'runs verification for both repository and wiki' do it 'runs verification for both repository and wiki' do
create(:repository_state, project: project, repository_verification_checksum: 'my_checksum', wiki_verification_checksum: 'my_checksum') stub_exclusive_lease
service =
instance_double(Geo::RepositoryVerificationSecondaryService, execute: true)
expect(Geo::RepositoryVerifySecondaryService).to receive(:new).with(registry, :repository).and_call_original allow(Geo::RepositoryVerificationSecondaryService)
expect(Geo::RepositoryVerifySecondaryService).to receive(:new).with(registry, :wiki).and_call_original .to receive(:new)
.with(registry, :repository)
.and_return(service)
allow(Geo::RepositoryVerificationSecondaryService)
.to receive(:new)
.with(registry, :wiki)
.and_return(service)
subject.perform(registry.id) subject.perform(registry.id)
expect(service).to have_received(:execute).twice
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