Refactor legacy finder to find registries retrying verification

These changes use the new finder when FDW is enabled without selective
sync to avoid code duplication.
parent caedbddd
...@@ -22,30 +22,16 @@ module Geo ...@@ -22,30 +22,16 @@ module Geo
end end
def execute def execute
if selective_sync?
registries_retrying_verification_for_selective_sync
else
registries_retrying_verification
end
end
private
attr_reader :type
def registries_retrying_verification
Geo::ProjectRegistry.retrying_verification(type)
end
# rubocop: disable CodeReuse/ActiveRecord
def registries_retrying_verification_for_selective_sync
legacy_inner_join_registry_ids( legacy_inner_join_registry_ids(
registries_retrying_verification, Geo::ProjectRegistry.retrying_verification(type),
current_node.projects.pluck(:id), current_node.projects.pluck_primary_key,
Geo::ProjectRegistry, Geo::ProjectRegistry,
foreign_key: :project_id foreign_key: :project_id
) )
end end
# rubocop: enable CodeReuse/ActiveRecord
private
attr_reader :type
end end
end end
...@@ -3,8 +3,6 @@ ...@@ -3,8 +3,6 @@
require 'spec_helper' require 'spec_helper'
describe Geo::LegacyProjectRegistryRetryingVerificationFinder, :geo do describe Geo::LegacyProjectRegistryRetryingVerificationFinder, :geo do
include EE::GeoHelpers
describe '#execute' do describe '#execute' do
let(:node) { create(:geo_node) } let(:node) { create(:geo_node) }
let(:group_1) { create(:group) } let(:group_1) { create(:group) }
...@@ -22,98 +20,78 @@ describe Geo::LegacyProjectRegistryRetryingVerificationFinder, :geo do ...@@ -22,98 +20,78 @@ describe Geo::LegacyProjectRegistryRetryingVerificationFinder, :geo do
let!(:repository_retrying_verification_broken_shard) { create(:geo_project_registry, :repository_retrying_verification, :wiki_verified, project: project_5) } let!(:repository_retrying_verification_broken_shard) { create(:geo_project_registry, :repository_retrying_verification, :wiki_verified, project: project_5) }
let!(:verified) { create(:geo_project_registry, :repository_verified, :wiki_verified) } let!(:verified) { create(:geo_project_registry, :repository_verified, :wiki_verified) }
shared_examples 'finds registries retrying verification' do context 'with repository type' do
context 'with repository type' do subject { described_class.new(current_node: node, type: :repository) }
subject { described_class.new(current_node: node, type: :repository) }
context 'without selective sync' do context 'without selective sync' do
it 'returns all registries retrying verification' do it 'returns all registries retrying verification' do
expect(subject.execute).to contain_exactly(retrying_verification, repository_retrying_verification, repository_retrying_verification_broken_shard) expect(subject.execute).to contain_exactly(retrying_verification, repository_retrying_verification, repository_retrying_verification_broken_shard)
end
end
context 'with selective sync by namespace' do
it 'returns registries retrying verification where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(retrying_verification, repository_retrying_verification)
end
end end
end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
it 'returns registries retrying verification where projects belongs to the shards' do it 'returns registries retrying verification where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(repository_retrying_verification_broken_shard) expect(subject.execute).to contain_exactly(retrying_verification, repository_retrying_verification)
end
end end
end end
context 'with wiki type' do context 'with selective sync by shard' do
subject { described_class.new(current_node: node, type: :wiki) } it 'returns registries retrying verification where projects belongs to the shards' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
context 'without selective sync' do expect(subject.execute).to contain_exactly(repository_retrying_verification_broken_shard)
it 'returns all registries retrying verification' do
expect(subject.execute).to contain_exactly(retrying_verification, wiki_retrying_verification, wiki_retrying_verification_broken_shard)
end
end end
end
end
context 'with selective sync by namespace' do context 'with wiki type' do
it 'returns registries retrying verification where projects belongs to the namespaces' do subject { described_class.new(current_node: node, type: :wiki) }
node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(retrying_verification, wiki_retrying_verification) context 'without selective sync' do
end it 'returns all registries retrying verification' do
expect(subject.execute).to contain_exactly(retrying_verification, wiki_retrying_verification, wiki_retrying_verification_broken_shard)
end end
end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
it 'returns registries retrying verification where projects belongs to the shards' do it 'returns registries retrying verification where projects belongs to the namespaces' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) node.update!(selective_sync_type: 'namespaces', namespaces: [group_1, nested_group_1])
expect(subject.execute).to contain_exactly(wiki_retrying_verification_broken_shard) expect(subject.execute).to contain_exactly(retrying_verification, wiki_retrying_verification)
end
end end
end end
context 'with invalid type' do context 'with selective sync by shard' do
subject { described_class.new(current_node: node, type: :invalid) } it 'returns registries retrying verification where projects belongs to the shards' do
node.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
context 'without selective sync' do expect(subject.execute).to contain_exactly(wiki_retrying_verification_broken_shard)
it 'returns nothing' do
expect(subject.execute).to be_empty
end
end end
end
end
context 'with selective sync by namespace' do context 'with invalid type' do
it 'returns nothing' do subject { described_class.new(current_node: node, type: :invalid) }
expect(subject.execute).to be_empty
end
end
context 'with selective sync by shard' do context 'without selective sync' do
it 'returns nothing' do it 'returns nothing' do
expect(subject.execute).to be_empty expect(subject.execute).to be_empty
end
end end
end end
end
# Disable transactions via :delete method because a foreign table context 'with selective sync by namespace' do
# can't see changes inside a transaction of a different connection. it 'returns nothing' do
context 'FDW', :delete do expect(subject.execute).to be_empty
before do end
skip('FDW is not configured') unless Gitlab::Geo::Fdw.enabled?
end end
include_examples 'finds registries retrying verification' context 'with selective sync by shard' do
end it 'returns nothing' do
expect(subject.execute).to be_empty
context 'Legacy' do end
before do
stub_fdw_disabled
end end
include_examples 'finds registries retrying verification'
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