Commit a12ca22a authored by Michael Kozono's avatar Michael Kozono

Refactor ProjectRegistryFinder spec

In order to consistently test it with and without FDW enabled.
parent e4c31f25
...@@ -24,7 +24,7 @@ module Geo ...@@ -24,7 +24,7 @@ module Geo
if use_legacy_queries? if use_legacy_queries?
legacy_find_synced_wikis legacy_find_synced_wikis
else else
fdw_find_enabled_wikis fdw_find_synced_wikis
end end
relation.count relation.count
...@@ -158,7 +158,7 @@ module Geo ...@@ -158,7 +158,7 @@ module Geo
end end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>] # @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_enabled_wikis def fdw_find_synced_wikis
Geo::ProjectRegistry.synced_wikis.where(fdw_enabled_wikis) Geo::ProjectRegistry.synced_wikis.where(fdw_enabled_wikis)
end end
......
...@@ -20,208 +20,202 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -20,208 +20,202 @@ describe Geo::ProjectRegistryFinder, :geo do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
end end
describe '#count_synced_repositories' do shared_examples 'counts all the things' do
it 'delegates to #find_synced_repositories' do describe '#count_synced_repositories' do
expect(subject).to receive(:find_synced_repositories).and_call_original it 'delegates to #find_synced_repositories' do
expect(subject).to receive(:find_synced_repositories).and_call_original
subject.count_synced_repositories subject.count_synced_repositories
end
it 'counts repositories that have been synced' do
create(:geo_project_registry, :sync_failed)
create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
expect(subject.count_synced_repositories).to eq 2
end
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
it 'delegates to #legacy_find_synced_repositories' do it 'counts repositories that have been synced' do
expect(subject).to receive(:legacy_find_synced_repositories).and_call_original create(:geo_project_registry, :sync_failed)
create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
subject.count_synced_repositories expect(subject.count_synced_repositories).to eq 2
end end
it 'counts projects that has been synced' do it 'counts synced wikis with nil wiki_access_level (which means enabled wiki)' do
project_1_in_synced_group = create(:project, group: synced_group) project_synced.project_feature.update!(wiki_access_level: nil)
project_2_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :synced, project: project_synced) create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, project: project_1_in_synced_group)
create(:geo_project_registry, :sync_failed, project: project_2_in_synced_group)
expect(subject.count_synced_repositories).to eq 1 expect(subject.count_synced_wikis).to eq 1
end end
end
end
describe '#count_synced_wikis' do context 'with selective sync' do
before do before do
allow(subject).to receive(:use_legacy_queries?).and_return(true) secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
it 'delegates to #legacy_find_synced_wikis' do it 'delegates to #legacy_find_synced_repositories' do
expect(subject).to receive(:legacy_find_synced_wikis).and_call_original expect(subject).to receive(:legacy_find_synced_repositories).and_call_original
subject.count_synced_wikis subject.count_synced_repositories
end end
it 'counts wiki that have been synced' do
create(:geo_project_registry, :sync_failed)
create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
expect(subject.count_synced_wikis).to eq 2 it 'counts projects that has been synced' do
end project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
it 'does not count disabled wikis' do create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, project: project_synced) create(:geo_project_registry, :synced, project: project_1_in_synced_group)
create(:geo_project_registry, :synced, project: create(:project, :wiki_disabled)) create(:geo_project_registry, :sync_failed, project: project_2_in_synced_group)
expect(subject.count_synced_wikis).to eq 1 expect(subject.count_synced_repositories).to eq 1
end
end
end end
it 'counts synced wikis with nil wiki_access_level (which means enabled wiki)' do describe '#count_synced_wikis' do
project_synced.project_feature.update!(wiki_access_level: nil) it 'delegates to the correct method' do
expect(subject).to receive("#{method_prefix}_find_synced_wikis".to_sym).and_call_original
create(:geo_project_registry, :synced, project: project_synced) subject.count_synced_wikis
end
expect(subject.count_synced_wikis).to eq 1 it 'counts wiki that have been synced' do
end create(:geo_project_registry, :sync_failed)
create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
context 'with selective sync' do expect(subject.count_synced_wikis).to eq 2
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
it 'delegates to #legacy_find_synced_wiki' do it 'counts synced wikis with nil wiki_access_level (which means enabled wiki)' do
expect(subject).to receive(:legacy_find_synced_wikis).and_call_original project_synced.project_feature.update!(wiki_access_level: nil)
subject.count_synced_wikis create(:geo_project_registry, :synced, project: project_synced)
end
it 'counts projects that has been synced' do expect(subject.count_synced_wikis).to eq 1
project_1_in_synced_group = create(:project, group: synced_group) end
project_2_in_synced_group = create(:project, group: synced_group)
it 'does not count disabled wikis' do
create(:geo_project_registry, :synced, project: project_synced) create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, project: project_1_in_synced_group) create(:geo_project_registry, :synced, project: create(:project, :wiki_disabled))
create(:geo_project_registry, :sync_failed, project: project_2_in_synced_group)
expect(subject.count_synced_wikis).to eq 1 expect(subject.count_synced_wikis).to eq 1
end end
end
end
describe '#count_failed_repositories' do context 'with selective sync' do
it 'delegates to #find_failed_project_registries' do before do
expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
subject.count_failed_repositories it 'delegates to #legacy_find_synced_wiki' do
end expect(subject).to receive(:legacy_find_synced_wikis).and_call_original
it 'counts projects that sync has failed' do subject.count_synced_wikis
create(:geo_project_registry, :synced) end
create(:geo_project_registry, :sync_failed, project: project_synced)
create(:geo_project_registry, :repository_sync_failed, project: project_repository_dirty)
create(:geo_project_registry, :wiki_sync_failed, project: project_wiki_dirty)
expect(subject.count_failed_repositories).to eq 2 it 'counts projects that has been synced' do
end project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, project: project_1_in_synced_group)
create(:geo_project_registry, :sync_failed, project: project_2_in_synced_group)
context 'with selective sync' do expect(subject.count_synced_wikis).to eq 1
before do end
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
end
it 'delegates to #find_failed_repositories' do describe '#count_failed_repositories' do
it 'delegates to #find_failed_project_registries' do
expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original
subject.count_failed_repositories subject.count_failed_repositories
end end
it 'counts projects that sync has failed' do it 'counts projects that sync has failed' do
project_1_in_synced_group = create(:project, group: synced_group) create(:geo_project_registry, :synced)
project_2_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :sync_failed, project: project_synced) create(:geo_project_registry, :sync_failed, project: project_synced)
create(:geo_project_registry, :repository_sync_failed, project: project_1_in_synced_group) create(:geo_project_registry, :repository_sync_failed, project: project_repository_dirty)
create(:geo_project_registry, :synced, project: project_2_in_synced_group) create(:geo_project_registry, :wiki_sync_failed, project: project_wiki_dirty)
expect(subject.count_failed_repositories).to eq 1 expect(subject.count_failed_repositories).to eq 2
end end
end
end
describe '#count_failed_wikis' do context 'with selective sync' do
it 'delegates to #find_failed_project_registries' do before do
expect(subject).to receive(:find_failed_project_registries).with('wiki').and_call_original secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
subject.count_failed_wikis it 'delegates to #find_failed_repositories' do
end expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original
it 'counts projects that sync has failed' do subject.count_failed_repositories
create(:geo_project_registry, :synced) end
create(:geo_project_registry, :sync_failed, project: project_synced)
create(:geo_project_registry, :repository_sync_failed, project: project_repository_dirty)
create(:geo_project_registry, :wiki_sync_failed, project: project_wiki_dirty)
expect(subject.count_failed_wikis).to eq 2 it 'counts projects that sync has failed' do
end project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :sync_failed, project: project_synced)
create(:geo_project_registry, :repository_sync_failed, project: project_1_in_synced_group)
create(:geo_project_registry, :synced, project: project_2_in_synced_group)
context 'with selective sync' do expect(subject.count_failed_repositories).to eq 1
before do end
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
end
it 'delegates to #find_failed_wikis' do describe '#count_failed_wikis' do
it 'delegates to #find_failed_project_registries' do
expect(subject).to receive(:find_failed_project_registries).with('wiki').and_call_original expect(subject).to receive(:find_failed_project_registries).with('wiki').and_call_original
subject.count_failed_wikis subject.count_failed_wikis
end end
it 'counts projects that sync has failed' do it 'counts projects that sync has failed' do
project_1_in_synced_group = create(:project, group: synced_group) create(:geo_project_registry, :synced)
project_2_in_synced_group = create(:project, group: synced_group)
create(:geo_project_registry, :sync_failed, project: project_synced) create(:geo_project_registry, :sync_failed, project: project_synced)
create(:geo_project_registry, :wiki_sync_failed, project: project_1_in_synced_group) create(:geo_project_registry, :repository_sync_failed, project: project_repository_dirty)
create(:geo_project_registry, :synced, project: project_2_in_synced_group) create(:geo_project_registry, :wiki_sync_failed, project: project_wiki_dirty)
expect(subject.count_failed_wikis).to eq 1 expect(subject.count_failed_wikis).to eq 2
end end
end
end
describe '#count_verified_repositories' do context 'with selective sync' do
it 'delegates to #find_verified_repositories when use_legacy_queries is false' do before do
expect(subject).to receive(:use_legacy_queries?).and_return(false) secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
expect(subject).to receive(:find_verified_repositories).and_call_original it 'delegates to #find_failed_wikis' do
expect(subject).to receive(:find_failed_project_registries).with('wiki').and_call_original
subject.count_verified_repositories subject.count_failed_wikis
end end
it 'counts projects that sync has failed' do
project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
it 'counts projects that verified' do create(:geo_project_registry, :sync_failed, project: project_synced)
create(:geo_project_registry, :repository_verified, project: project_repository_verified) create(:geo_project_registry, :wiki_sync_failed, project: project_1_in_synced_group)
create(:geo_project_registry, :repository_verified, project: build(:project)) create(:geo_project_registry, :synced, project: project_2_in_synced_group)
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed)
expect(subject.count_verified_repositories).to eq 2 expect(subject.count_failed_wikis).to eq 1
end
end
end end
context 'with legacy queries' do describe '#count_verified_repositories' do
before do it 'delegates to #find_verified_repositories when use_legacy_queries is false' do
allow(subject).to receive(:use_legacy_queries?).and_return(true) expect(subject).to receive(:use_legacy_queries?).and_return(false)
expect(subject).to receive(:find_verified_repositories).and_call_original
subject.count_verified_repositories
end end
it 'delegates to #legacy_find_verified_repositories' do it 'delegates to #legacy_find_verified_repositories when use_legacy_queries is true' do
expect(subject).to receive(:use_legacy_queries?).and_return(true)
expect(subject).to receive(:legacy_find_verified_repositories).and_call_original expect(subject).to receive(:legacy_find_verified_repositories).and_call_original
subject.count_verified_repositories subject.count_verified_repositories
...@@ -235,60 +229,60 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -235,60 +229,60 @@ describe Geo::ProjectRegistryFinder, :geo do
expect(subject.count_verified_repositories).to eq 2 expect(subject.count_verified_repositories).to eq 2
end end
end end
end
describe '#count_verified_wikis' do describe '#count_verified_wikis' do
before do it 'delegates to the correct method' do
allow(subject).to receive(:use_legacy_queries?).and_return(true) expect(subject).to receive("#{method_prefix}_find_verified_wikis".to_sym).and_call_original
end
it 'delegates to #legacy_find_synced_wikis' do subject.count_verified_wikis
expect(subject).to receive(:legacy_find_verified_wikis).and_call_original end
subject.count_verified_wikis it 'counts wikis that verified' do
end create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verified, project: build(:project))
create(:geo_project_registry, :wiki_verification_failed, project: project_wiki_verification_failed)
it 'counts wikis that verified' do expect(subject.count_verified_wikis).to eq 2
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified) end
create(:geo_project_registry, :wiki_verified, project: build(:project))
create(:geo_project_registry, :wiki_verification_failed, project: project_wiki_verification_failed)
expect(subject.count_verified_wikis).to eq 2 it 'does not count disabled wikis' do
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verified, project: create(:project, :wiki_disabled))
expect(subject.count_verified_wikis).to eq 1
end
end end
it 'does not count disabled wikis' do describe '#count_verification_failed_repositories' do
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified) it 'delegates to #find_verification_failed_project_registries' do
create(:geo_project_registry, :wiki_verified, project: create(:project, :wiki_disabled)) expect(subject).to receive(:find_verification_failed_project_registries).with('repository').and_call_original
expect(subject.count_verified_wikis).to eq 1 subject.count_verification_failed_repositories
end end
end
describe '#count_verification_failed_repositories' do it 'delegates to #legacy_find_filtered_verification_failed_projects when use_legacy_queries is true' do
it 'delegates to #find_verification_failed_project_registries' do expect(subject).to receive(:use_legacy_queries?).and_return(true)
expect(subject).to receive(:find_verification_failed_project_registries).with('repository').and_call_original
subject.count_verification_failed_repositories expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).with('repository').and_call_original
end
subject.count_verification_failed_repositories
end
it 'counts projects that verification has failed' do it 'delegates to #find_filtered_verification_failed_project_registries when use_legacy_queries is false' do
create(:geo_project_registry, :repository_verified, project: project_repository_verified) expect(subject).to receive(:use_legacy_queries?).and_return(false)
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed)
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verification_failed, project: project_wiki_verification_failed)
expect(subject.count_verification_failed_repositories).to eq 1 expect(subject).to receive(:find_filtered_verification_failed_project_registries).with('repository').and_call_original
end
context 'with legacy queries' do subject.count_verification_failed_repositories
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
end end
it 'delegates to #legacy_find_filtered_verification_failed_projects' do it 'counts projects that verification has failed' do
expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).and_call_original create(:geo_project_registry, :repository_verified, project: project_repository_verified)
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed)
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verification_failed, project: project_wiki_verification_failed)
subject.find_verification_failed_project_registries('repository') expect(subject.count_verification_failed_repositories).to eq 1
end end
it 'counts projects that verification has failed' do it 'counts projects that verification has failed' do
...@@ -300,33 +294,28 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -300,33 +294,28 @@ describe Geo::ProjectRegistryFinder, :geo do
expect(subject.count_verification_failed_repositories).to eq 1 expect(subject.count_verification_failed_repositories).to eq 1
end end
end end
end
describe '#count_verification_failed_wikis' do describe '#count_verification_failed_wikis' do
it 'delegates to #find_verification_failed_project_registries' do it 'delegates to #find_verification_failed_project_registries' do
expect(subject).to receive(:find_verification_failed_project_registries).with('wiki').and_call_original expect(subject).to receive(:find_verification_failed_project_registries).with('wiki').and_call_original
subject.count_verification_failed_wikis subject.count_verification_failed_wikis
end end
it 'counts projects that verification has failed' do it 'delegates to #legacy_find_filtered_verification_failed_projects when use_legacy_queries is true' do
create(:geo_project_registry, :repository_verified, project: project_repository_verified) expect(subject).to receive(:use_legacy_queries?).and_return(true)
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed)
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verification_failed, project: project_wiki_verification_failed)
expect(subject.count_verification_failed_wikis).to eq 1 expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).with('wiki').and_call_original
end
context 'with legacy queries' do subject.count_verification_failed_wikis
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
end end
it 'delegates to #legacy_find_filtered_verification_failed_projects' do it 'delegates to #find_filtered_verification_failed_project_registries when use_legacy_queries is false' do
expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).and_call_original expect(subject).to receive(:use_legacy_queries?).and_return(false)
expect(subject).to receive(:find_filtered_verification_failed_project_registries).with('wiki').and_call_original
subject.find_verification_failed_project_registries('wiki') subject.count_verification_failed_wikis
end end
it 'counts projects that verification has failed' do it 'counts projects that verification has failed' do
...@@ -340,279 +329,258 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -340,279 +329,258 @@ describe Geo::ProjectRegistryFinder, :geo do
end end
end end
describe '#find_failed_project_registries' do shared_examples 'finds all the things' do
let(:project_1_in_synced_group) { create(:project, group: synced_group) } describe '#find_unsynced_projects' do
let(:project_2_in_synced_group) { create(:project, group: synced_group) } it 'delegates to the correct method' do
expect(subject).to receive("#{method_prefix}_find_unsynced_projects".to_sym).and_call_original
let!(:synced) { create(:geo_project_registry, :synced) } subject.find_unsynced_projects(batch_size: 10)
let!(:sync_failed) { create(:geo_project_registry, :sync_failed, project: project_synced) } end
let!(:repository_sync_failed) { create(:geo_project_registry, :repository_sync_failed, project: project_1_in_synced_group) }
let!(:wiki_sync_failed) { create(:geo_project_registry, :wiki_sync_failed, project: project_2_in_synced_group) }
it 'delegates to #find_failed_project_registries' do it 'returns projects without an entry on the tracking database' do
expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
subject.count_failed_repositories projects = subject.find_unsynced_projects(batch_size: 10)
end
it 'returns only project registries that repository sync has failed' do expect(projects).to match_ids(project_not_synced)
expect(subject.find_failed_project_registries('repository')).to match_array([sync_failed, repository_sync_failed]) end
end
it 'returns only project registries that wiki sync has failed' do context 'with selective sync' do
expect(subject.find_failed_project_registries('wiki')).to match_array([sync_failed, wiki_sync_failed]) before do
end secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
context 'with selective sync' do it 'delegates to #legacy_find_unsynced_projects' do
before do expect(subject).to receive(:legacy_find_unsynced_projects).and_call_original
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'delegates to #legacy_find_filtered_failed_projects' do subject.find_unsynced_projects(batch_size: 10)
expect(subject).to receive(:legacy_find_filtered_failed_projects).and_call_original end
subject.find_failed_project_registries it 'returns untracked projects in the synced group' do
end project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
it 'returns project registries that sync has failed' do create(:geo_project_registry, :sync_failed, project: project_1_in_synced_group)
expect(subject.find_failed_project_registries).to match_array([repository_sync_failed, wiki_sync_failed])
end
it 'returns only project registries that repository sync has failed' do projects = subject.find_unsynced_projects(batch_size: 10)
create(:geo_project_registry, :repository_sync_failed)
expect(subject.find_failed_project_registries('repository')).to match_array([repository_sync_failed]) expect(projects).to match_ids(project_2_in_synced_group)
end
end end
end
it 'returns only project registries that wiki sync has failed' do describe '#find_projects_updated_recently' do
create(:geo_project_registry, :wiki_sync_failed) it 'delegates to the correct method' do
expect(subject).to receive("#{method_prefix}_find_projects_updated_recently".to_sym).and_call_original
expect(subject.find_failed_project_registries('wiki')).to match_array([wiki_sync_failed]) subject.find_projects_updated_recently(batch_size: 10)
end end
end
end
shared_examples 'find outdated registries for repositories/wikis' do it 'returns projects with a dirty entry on the tracking database' do
it 'does not return registries that are verified on primary and secondary' do create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
project_verified = create(:repository_state, :repository_verified, :wiki_verified).project create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
repository_verified = create(:repository_state, :repository_verified).project
wiki_verified = create(:repository_state, :wiki_verified).project
create(:geo_project_registry, :repository_verified, :wiki_verified, project: project_verified) projects = subject.find_projects_updated_recently(batch_size: 10)
create(:geo_project_registry, :repository_verified, project: repository_verified)
create(:geo_project_registry, :wiki_verified, project: wiki_verified)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty expect(projects).to match_ids([project_repository_dirty, project_wiki_dirty])
end end
it 'does not return registries that were unverified/outdated on primary' do context 'with selective sync' do
project_unverified_primary = create(:project) before do
project_outdated_primary = create(:repository_state, :repository_outdated, :wiki_outdated).project secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
repository_outdated_primary = create(:repository_state, :repository_outdated, :wiki_verified).project end
wiki_outdated_primary = create(:repository_state, :repository_verified, :wiki_outdated).project
create(:geo_project_registry, project: project_unverified_primary) it 'delegates to #legacy_find_projects_updated_recently' do
create(:geo_project_registry, :repository_verification_outdated, :wiki_verification_outdated, project: project_outdated_primary) expect(subject).to receive(:legacy_find_projects_updated_recently).and_call_original
create(:geo_project_registry, :repository_verified, :wiki_verified, project: repository_outdated_primary)
create(:geo_project_registry, :repository_verified, :wiki_verified, project: wiki_outdated_primary)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty subject.find_projects_updated_recently(batch_size: 10)
end end
it 'returns registries that were unverified/outdated on secondary' do it 'returns dirty projects in the synced group' do
# Secondary unverified/outdated project_1_in_synced_group = create(:project, group: synced_group)
project_unverified_secondary = create(:repository_state, :repository_verified, :wiki_verified).project project_2_in_synced_group = create(:project, group: synced_group)
project_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project project_3_in_synced_group = create(:project, group: synced_group)
repository_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project create(:project, group: synced_group)
wiki_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
registry_unverified_secondary = create(:geo_project_registry, project: project_unverified_secondary)
registry_outdated_secondary = create(:geo_project_registry, :repository_verification_outdated, :wiki_verification_outdated, project: project_outdated_secondary)
registry_repository_outdated_secondary = create(:geo_project_registry, :repository_verification_outdated, :wiki_verified, project: repository_outdated_secondary)
registry_wiki_outdated_secondary = create(:geo_project_registry, :repository_verified, :wiki_verification_outdated, project: wiki_outdated_secondary)
expect(subject.find_registries_to_verify(batch_size: 100))
.to match_array([
registry_unverified_secondary,
registry_outdated_secondary,
registry_repository_outdated_secondary,
registry_wiki_outdated_secondary
])
end
it 'does not return registries that failed on primary' do create(:geo_project_registry, :synced, :repository_dirty, project: project_1_in_synced_group)
verification_failed_primary = create(:repository_state, :repository_failed, :wiki_failed).project create(:geo_project_registry, :synced, :wiki_dirty, project: project_2_in_synced_group)
create(:geo_project_registry, :synced, project: project_3_in_synced_group)
create(:geo_project_registry, project: verification_failed_primary) projects = subject.find_projects_updated_recently(batch_size: 10)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty expect(projects).to match_ids(project_1_in_synced_group, project_2_in_synced_group)
end
end
end end
it 'returns registries where one failed and one verified on the primary' do describe '#find_failed_project_registries' do
verification_failed_primary = create(:repository_state, :repository_failed, :wiki_failed).project let(:project_1_in_synced_group) { create(:project, group: synced_group) }
repository_failed_primary = create(:repository_state, :repository_failed, :wiki_verified).project let(:project_2_in_synced_group) { create(:project, group: synced_group) }
wiki_failed_primary = create(:repository_state, :repository_verified, :wiki_failed).project
create(:geo_project_registry, project: verification_failed_primary) let!(:synced) { create(:geo_project_registry, :synced) }
registry_repository_failed_primary = create(:geo_project_registry, project: repository_failed_primary) let!(:sync_failed) { create(:geo_project_registry, :sync_failed, project: project_synced) }
registry_wiki_failed_primary = create(:geo_project_registry, project: wiki_failed_primary) let!(:repository_sync_failed) { create(:geo_project_registry, :repository_sync_failed, project: project_1_in_synced_group) }
let!(:wiki_sync_failed) { create(:geo_project_registry, :wiki_sync_failed, project: project_2_in_synced_group) }
expect(subject.find_registries_to_verify(batch_size: 100)) it 'delegates to #find_failed_project_registries' do
.to match_array([ expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original
registry_repository_failed_primary,
registry_wiki_failed_primary
])
end
it 'does not return registries where verification failed on secondary' do subject.count_failed_repositories
# Verification failed on secondary end
verification_failed_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
repository_failed_secondary = create(:repository_state, :repository_verified).project
wiki_failed_secondary = create(:repository_state, :wiki_verified).project
create(:geo_project_registry, :repository_verification_failed, :wiki_verification_failed, project: verification_failed_secondary) it 'returns only project registries that repository sync has failed' do
create(:geo_project_registry, :repository_verification_failed, project: repository_failed_secondary) expect(subject.find_failed_project_registries('repository')).to match_array([sync_failed, repository_sync_failed])
create(:geo_project_registry, :wiki_verification_failed, project: wiki_failed_secondary) end
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty it 'returns only project registries that wiki sync has failed' do
end expect(subject.find_failed_project_registries('wiki')).to match_array([sync_failed, wiki_sync_failed])
end end
# Disable transactions via :delete method because a foreign table context 'with selective sync' do
# can't see changes inside a transaction of a different connection. before do
context 'FDW', :delete do secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
before do end
skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo::Fdw.enabled?
end
describe '#fdw_find_enabled_wikis' do it 'delegates to #legacy_find_filtered_failed_projects' do
it 'does not count disabled wikis' do expect(subject).to receive(:legacy_find_filtered_failed_projects).and_call_original
expect(subject).to receive(:fdw_find_enabled_wikis).and_call_original
create(:geo_project_registry, :synced, project: project_synced) subject.find_failed_project_registries
create(:geo_project_registry, :synced, project: create(:project, :wiki_disabled)) end
expect(subject.count_synced_wikis).to eq 1 it 'returns project registries that sync has failed' do
end expect(subject.find_failed_project_registries).to match_array([repository_sync_failed, wiki_sync_failed])
end
it 'counts synced wikis with nil wiki_access_level (which means enabled wiki)' do it 'returns only project registries that repository sync has failed' do
project_synced.project_feature.update!(wiki_access_level: nil) create(:geo_project_registry, :repository_sync_failed)
create(:geo_project_registry, :synced, project: project_synced) expect(subject.find_failed_project_registries('repository')).to match_array([repository_sync_failed])
end
expect(subject.count_synced_wikis).to eq 1 it 'returns only project registries that wiki sync has failed' do
create(:geo_project_registry, :wiki_sync_failed)
expect(subject.find_failed_project_registries('wiki')).to match_array([wiki_sync_failed])
end
end end
end end
describe '#fdw_find_verified_wikis' do describe '#find_registries_to_verify' do
it 'does not count disabled wikis' do it 'delegates to the correct method' do
expect(subject).to receive(:fdw_find_verified_wikis).and_call_original expect(subject).to receive("#{method_prefix}_find_registries_to_verify".to_sym).and_call_original
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verified, project: create(:project, :wiki_disabled))
expect(subject.count_verified_wikis).to eq 1 subject.find_registries_to_verify(batch_size: 10)
end end
end
describe '#find_unsynced_projects' do it 'does not return registries that are verified on primary and secondary' do
it 'delegates to #fdw_find_unsynced_projects' do project_verified = create(:repository_state, :repository_verified, :wiki_verified).project
expect(subject).to receive(:fdw_find_unsynced_projects).and_call_original repository_verified = create(:repository_state, :repository_verified).project
wiki_verified = create(:repository_state, :wiki_verified).project
subject.find_unsynced_projects(batch_size: 10) create(:geo_project_registry, :repository_verified, :wiki_verified, project: project_verified)
create(:geo_project_registry, :repository_verified, project: repository_verified)
create(:geo_project_registry, :wiki_verified, project: wiki_verified)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end end
it 'delegates to #legacy_find_unsynced_projects when node has selective sync' do it 'does not return registries that were unverified/outdated on primary' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) project_unverified_primary = create(:project)
project_outdated_primary = create(:repository_state, :repository_outdated, :wiki_outdated).project
repository_outdated_primary = create(:repository_state, :repository_outdated, :wiki_verified).project
wiki_outdated_primary = create(:repository_state, :repository_verified, :wiki_outdated).project
expect(subject).to receive(:legacy_find_unsynced_projects).and_call_original create(:geo_project_registry, project: project_unverified_primary)
create(:geo_project_registry, :repository_verification_outdated, :wiki_verification_outdated, project: project_outdated_primary)
create(:geo_project_registry, :repository_verified, :wiki_verified, project: repository_outdated_primary)
create(:geo_project_registry, :repository_verified, :wiki_verified, project: wiki_outdated_primary)
subject.find_unsynced_projects(batch_size: 10) expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end end
it 'returns projects without an entry on the tracking database' do it 'returns registries that were unverified/outdated on secondary' do
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty) # Secondary unverified/outdated
project_unverified_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
project_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
repository_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
wiki_outdated_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
projects = subject.find_unsynced_projects(batch_size: 10) registry_unverified_secondary = create(:geo_project_registry, project: project_unverified_secondary)
registry_outdated_secondary = create(:geo_project_registry, :repository_verification_outdated, :wiki_verification_outdated, project: project_outdated_secondary)
registry_repository_outdated_secondary = create(:geo_project_registry, :repository_verification_outdated, :wiki_verified, project: repository_outdated_secondary)
registry_wiki_outdated_secondary = create(:geo_project_registry, :repository_verified, :wiki_verification_outdated, project: wiki_outdated_secondary)
expect(projects.count).to eq(1) expect(subject.find_registries_to_verify(batch_size: 100))
expect(projects.first.id).to eq(project_not_synced.id) .to match_array([
registry_unverified_secondary,
registry_outdated_secondary,
registry_repository_outdated_secondary,
registry_wiki_outdated_secondary
])
end end
end
describe '#find_projects_updated_recently' do it 'does not return registries that failed on primary' do
it 'delegates to #fdw_find_projects_updated_recently' do verification_failed_primary = create(:repository_state, :repository_failed, :wiki_failed).project
expect(subject).to receive(:fdw_find_projects_updated_recently).and_call_original
subject.find_projects_updated_recently(batch_size: 10) create(:geo_project_registry, project: verification_failed_primary)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end end
it 'delegates to #legacy_find_projects_updated_recently when node has selective sync' do it 'returns registries where one failed and one verified on the primary' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) verification_failed_primary = create(:repository_state, :repository_failed, :wiki_failed).project
repository_failed_primary = create(:repository_state, :repository_failed, :wiki_verified).project
wiki_failed_primary = create(:repository_state, :repository_verified, :wiki_failed).project
expect(subject).to receive(:legacy_find_projects_updated_recently).and_call_original create(:geo_project_registry, project: verification_failed_primary)
registry_repository_failed_primary = create(:geo_project_registry, project: repository_failed_primary)
registry_wiki_failed_primary = create(:geo_project_registry, project: wiki_failed_primary)
subject.find_projects_updated_recently(batch_size: 10) expect(subject.find_registries_to_verify(batch_size: 100))
.to match_array([
registry_repository_failed_primary,
registry_wiki_failed_primary
])
end end
it 'returns projects with a dirty entry on the tracking database' do it 'does not return registries where verification failed on secondary' do
project_repository_dirty = create(:project) # Verification failed on secondary
project_wiki_dirty = create(:project) verification_failed_secondary = create(:repository_state, :repository_verified, :wiki_verified).project
repository_failed_secondary = create(:repository_state, :repository_verified).project
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty) wiki_failed_secondary = create(:repository_state, :wiki_verified).project
create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
projects = subject.find_projects_updated_recently(batch_size: 10) create(:geo_project_registry, :repository_verification_failed, :wiki_verification_failed, project: verification_failed_secondary)
create(:geo_project_registry, :repository_verification_failed, project: repository_failed_secondary)
create(:geo_project_registry, :wiki_verification_failed, project: wiki_failed_secondary)
expect(projects.pluck(:id)).to match_array([project_repository_dirty.id, project_wiki_dirty.id]) expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end end
end end
describe '#find_registries_to_verify' do
include_examples 'find outdated registries for repositories/wikis'
end
end end
context 'Legacy' do # Disable transactions via :delete method because a foreign table
# can't see changes inside a transaction of a different connection.
context 'FDW', :delete do
before do before do
allow(Gitlab::Geo::Fdw).to receive(:enabled?).and_return(false) skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo::Fdw.enabled?
end end
describe '#find_unsynced_projects' do include_examples 'counts all the things'
it 'delegates to #legacy_find_unsynced_projects' do
expect(subject).to receive(:legacy_find_unsynced_projects).and_call_original
subject.find_unsynced_projects(batch_size: 10) include_examples 'finds all the things' do
end let(:method_prefix) { 'fdw' }
it 'returns projects without an entry on the tracking database' do
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
projects = subject.find_unsynced_projects(batch_size: 10)
expect(projects).to match_array([project_not_synced])
end
end end
end
describe '#find_projects_updated_recently' do context 'Legacy' do
it 'delegates to #legacy_find_projects_updated_recently' do before do
expect(subject).to receive(:legacy_find_projects_updated_recently).and_call_original allow(Gitlab::Geo::Fdw).to receive(:enabled?).and_return(false)
subject.find_projects_updated_recently(batch_size: 10)
end
it 'returns projects with a dirty entry on the tracking database' do
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
projects = subject.find_projects_updated_recently(batch_size: 10)
expect(projects.pluck(:id)).to match_array([project_repository_dirty.id, project_wiki_dirty.id])
end
end end
describe '#find_registries_to_verify' do include_examples 'counts all the things'
include_examples 'find outdated registries for repositories/wikis'
include_examples 'finds all the things' do
let(:method_prefix) { 'legacy' }
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