Rename repository verification service on secondary node

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