Commit d82e30fa authored by Stan Hu's avatar Stan Hu

Merge branch 'mk/geo/refactor-project-registry-finder-spec' into 'master'

Geo: Refactor ProjectRegistryFinder spec

See merge request gitlab-org/gitlab-ee!5353
parents f97f2683 a12ca22a
......@@ -24,7 +24,7 @@ module Geo
if use_legacy_queries?
legacy_find_synced_wikis
else
fdw_find_enabled_wikis
fdw_find_synced_wikis
end
relation.count
......@@ -158,7 +158,7 @@ module Geo
end
# @return [ActiveRecord::Relation<Geo::ProjectRegistry>]
def fdw_find_enabled_wikis
def fdw_find_synced_wikis
Geo::ProjectRegistry.synced_wikis.where(fdw_enabled_wikis)
end
......
......@@ -20,208 +20,202 @@ describe Geo::ProjectRegistryFinder, :geo do
stub_current_geo_node(secondary)
end
describe '#count_synced_repositories' do
it 'delegates to #find_synced_repositories' do
expect(subject).to receive(:find_synced_repositories).and_call_original
shared_examples 'counts all the things' do
describe '#count_synced_repositories' do
it 'delegates to #find_synced_repositories' do
expect(subject).to receive(:find_synced_repositories).and_call_original
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])
subject.count_synced_repositories
end
it 'delegates to #legacy_find_synced_repositories' do
expect(subject).to receive(:legacy_find_synced_repositories).and_call_original
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)
subject.count_synced_repositories
expect(subject.count_synced_repositories).to eq 2
end
it 'counts projects that has been synced' do
project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
it 'counts synced wikis with nil wiki_access_level (which means enabled wiki)' do
project_synced.project_feature.update!(wiki_access_level: nil)
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
describe '#count_synced_wikis' do
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
end
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'delegates to #legacy_find_synced_wikis' do
expect(subject).to receive(:legacy_find_synced_wikis).and_call_original
it 'delegates to #legacy_find_synced_repositories' do
expect(subject).to receive(:legacy_find_synced_repositories).and_call_original
subject.count_synced_wikis
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)
subject.count_synced_repositories
end
expect(subject.count_synced_wikis).to eq 2
end
it 'counts projects that has been synced' do
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: create(:project, :wiki_disabled))
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_wikis).to eq 1
expect(subject.count_synced_repositories).to eq 1
end
end
end
it 'counts synced wikis with nil wiki_access_level (which means enabled wiki)' do
project_synced.project_feature.update!(wiki_access_level: nil)
describe '#count_synced_wikis' do
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
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)
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_synced_wikis).to eq 2
end
it 'delegates to #legacy_find_synced_wiki' do
expect(subject).to receive(:legacy_find_synced_wikis).and_call_original
it 'counts synced wikis with nil wiki_access_level (which means enabled wiki)' do
project_synced.project_feature.update!(wiki_access_level: nil)
subject.count_synced_wikis
end
create(:geo_project_registry, :synced, project: project_synced)
it 'counts projects that has been synced' do
project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
expect(subject.count_synced_wikis).to eq 1
end
it 'does not count disabled wikis' do
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)
create(:geo_project_registry, :synced, project: create(:project, :wiki_disabled))
expect(subject.count_synced_wikis).to eq 1
end
end
end
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
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
subject.count_failed_repositories
end
it 'delegates to #legacy_find_synced_wiki' do
expect(subject).to receive(:legacy_find_synced_wikis).and_call_original
it 'counts projects that sync has failed' do
create(:geo_project_registry, :synced)
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)
subject.count_synced_wikis
end
expect(subject.count_failed_repositories).to eq 2
end
it 'counts projects that has been synced' do
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
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_synced_wikis).to eq 1
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
subject.count_failed_repositories
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)
create(:geo_project_registry, :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, :synced, project: project_2_in_synced_group)
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 1
expect(subject.count_failed_repositories).to eq 2
end
end
end
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
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
subject.count_failed_wikis
end
it 'delegates to #find_failed_repositories' do
expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original
it 'counts projects that sync has failed' do
create(:geo_project_registry, :synced)
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)
subject.count_failed_repositories
end
expect(subject.count_failed_wikis).to eq 2
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)
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
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_failed_repositories).to eq 1
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
subject.count_failed_wikis
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)
create(:geo_project_registry, :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, :synced, project: project_2_in_synced_group)
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 1
expect(subject.count_failed_wikis).to eq 2
end
end
end
describe '#count_verified_repositories' do
it 'delegates to #find_verified_repositories when use_legacy_queries is false' do
expect(subject).to receive(:use_legacy_queries?).and_return(false)
context 'with selective sync' do
before do
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
end
subject.count_failed_wikis
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, :repository_verified, project: project_repository_verified)
create(:geo_project_registry, :repository_verified, project: build(:project))
create(:geo_project_registry, :repository_verification_failed, project: project_repository_verification_failed)
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, :synced, project: project_2_in_synced_group)
expect(subject.count_verified_repositories).to eq 2
expect(subject.count_failed_wikis).to eq 1
end
end
end
context 'with legacy queries' do
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
describe '#count_verified_repositories' do
it 'delegates to #find_verified_repositories when use_legacy_queries is false' do
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
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
subject.count_verified_repositories
......@@ -235,60 +229,60 @@ describe Geo::ProjectRegistryFinder, :geo do
expect(subject.count_verified_repositories).to eq 2
end
end
end
describe '#count_verified_wikis' do
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
end
describe '#count_verified_wikis' do
it 'delegates to the correct method' do
expect(subject).to receive("#{method_prefix}_find_verified_wikis".to_sym).and_call_original
it 'delegates to #legacy_find_synced_wikis' do
expect(subject).to receive(:legacy_find_verified_wikis).and_call_original
subject.count_verified_wikis
end
subject.count_verified_wikis
end
it 'counts wikis that verified' do
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
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)
expect(subject.count_verified_wikis).to eq 2
end
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
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))
describe '#count_verification_failed_repositories' do
it 'delegates to #find_verification_failed_project_registries' do
expect(subject).to receive(:find_verification_failed_project_registries).with('repository').and_call_original
expect(subject.count_verified_wikis).to eq 1
end
end
subject.count_verification_failed_repositories
end
describe '#count_verification_failed_repositories' do
it 'delegates to #find_verification_failed_project_registries' do
expect(subject).to receive(:find_verification_failed_project_registries).with('repository').and_call_original
it 'delegates to #legacy_find_filtered_verification_failed_projects when use_legacy_queries is true' do
expect(subject).to receive(:use_legacy_queries?).and_return(true)
subject.count_verification_failed_repositories
end
expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).with('repository').and_call_original
subject.count_verification_failed_repositories
end
it 'counts projects that verification has failed' do
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)
it 'delegates to #find_filtered_verification_failed_project_registries when use_legacy_queries is false' do
expect(subject).to receive(:use_legacy_queries?).and_return(false)
expect(subject.count_verification_failed_repositories).to eq 1
end
expect(subject).to receive(:find_filtered_verification_failed_project_registries).with('repository').and_call_original
context 'with legacy queries' do
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
subject.count_verification_failed_repositories
end
it 'delegates to #legacy_find_filtered_verification_failed_projects' do
expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).and_call_original
it 'counts projects that verification has failed' do
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
it 'counts projects that verification has failed' do
......@@ -300,33 +294,28 @@ describe Geo::ProjectRegistryFinder, :geo do
expect(subject.count_verification_failed_repositories).to eq 1
end
end
end
describe '#count_verification_failed_wikis' do
it 'delegates to #find_verification_failed_project_registries' do
expect(subject).to receive(:find_verification_failed_project_registries).with('wiki').and_call_original
describe '#count_verification_failed_wikis' do
it 'delegates to #find_verification_failed_project_registries' do
expect(subject).to receive(:find_verification_failed_project_registries).with('wiki').and_call_original
subject.count_verification_failed_wikis
end
subject.count_verification_failed_wikis
end
it 'counts projects that verification has failed' do
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)
it 'delegates to #legacy_find_filtered_verification_failed_projects when use_legacy_queries is true' do
expect(subject).to receive(:use_legacy_queries?).and_return(true)
expect(subject.count_verification_failed_wikis).to eq 1
end
expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).with('wiki').and_call_original
context 'with legacy queries' do
before do
allow(subject).to receive(:use_legacy_queries?).and_return(true)
subject.count_verification_failed_wikis
end
it 'delegates to #legacy_find_filtered_verification_failed_projects' do
expect(subject).to receive(:legacy_find_filtered_verification_failed_projects).and_call_original
it 'delegates to #find_filtered_verification_failed_project_registries when use_legacy_queries is false' do
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
it 'counts projects that verification has failed' do
......@@ -340,279 +329,258 @@ describe Geo::ProjectRegistryFinder, :geo do
end
end
describe '#find_failed_project_registries' do
let(:project_1_in_synced_group) { create(:project, group: synced_group) }
let(:project_2_in_synced_group) { create(:project, group: synced_group) }
shared_examples 'finds all the things' do
describe '#find_unsynced_projects' do
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) }
let!(:sync_failed) { create(:geo_project_registry, :sync_failed, project: project_synced) }
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) }
subject.find_unsynced_projects(batch_size: 10)
end
it 'delegates to #find_failed_project_registries' do
expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original
it 'returns projects without an entry on the tracking database' do
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
subject.count_failed_repositories
end
projects = subject.find_unsynced_projects(batch_size: 10)
it 'returns only project registries that repository sync has failed' do
expect(subject.find_failed_project_registries('repository')).to match_array([sync_failed, repository_sync_failed])
end
expect(projects).to match_ids(project_not_synced)
end
it 'returns only project registries that wiki sync has failed' do
expect(subject.find_failed_project_registries('wiki')).to match_array([sync_failed, wiki_sync_failed])
end
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'delegates to #legacy_find_unsynced_projects' do
expect(subject).to receive(:legacy_find_unsynced_projects).and_call_original
it 'delegates to #legacy_find_filtered_failed_projects' do
expect(subject).to receive(:legacy_find_filtered_failed_projects).and_call_original
subject.find_unsynced_projects(batch_size: 10)
end
subject.find_failed_project_registries
end
it 'returns untracked projects in the synced group' do
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
expect(subject.find_failed_project_registries).to match_array([repository_sync_failed, wiki_sync_failed])
end
create(:geo_project_registry, :sync_failed, project: project_1_in_synced_group)
it 'returns only project registries that repository sync has failed' do
create(:geo_project_registry, :repository_sync_failed)
projects = subject.find_unsynced_projects(batch_size: 10)
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
it 'returns only project registries that wiki sync has failed' do
create(:geo_project_registry, :wiki_sync_failed)
describe '#find_projects_updated_recently' do
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
shared_examples 'find outdated registries for repositories/wikis' do
it 'does not return registries that are verified on primary and secondary' do
project_verified = create(:repository_state, :repository_verified, :wiki_verified).project
repository_verified = create(:repository_state, :repository_verified).project
wiki_verified = create(:repository_state, :wiki_verified).project
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)
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)
projects = subject.find_projects_updated_recently(batch_size: 10)
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end
expect(projects).to match_ids([project_repository_dirty, project_wiki_dirty])
end
it 'does not return registries that were unverified/outdated on primary' do
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
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
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)
it 'delegates to #legacy_find_projects_updated_recently' do
expect(subject).to receive(:legacy_find_projects_updated_recently).and_call_original
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end
subject.find_projects_updated_recently(batch_size: 10)
end
it 'returns registries that were unverified/outdated on secondary' do
# 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
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 'returns dirty projects in the synced group' do
project_1_in_synced_group = create(:project, group: synced_group)
project_2_in_synced_group = create(:project, group: synced_group)
project_3_in_synced_group = create(:project, group: synced_group)
create(:project, group: synced_group)
it 'does not return registries that failed on primary' do
verification_failed_primary = create(:repository_state, :repository_failed, :wiki_failed).project
create(:geo_project_registry, :synced, :repository_dirty, project: project_1_in_synced_group)
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
it 'returns registries where one failed and one verified on the primary' do
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
describe '#find_failed_project_registries' do
let(:project_1_in_synced_group) { create(:project, group: synced_group) }
let(:project_2_in_synced_group) { create(:project, group: synced_group) }
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)
let!(:synced) { create(:geo_project_registry, :synced) }
let!(:sync_failed) { create(:geo_project_registry, :sync_failed, project: project_synced) }
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))
.to match_array([
registry_repository_failed_primary,
registry_wiki_failed_primary
])
end
it 'delegates to #find_failed_project_registries' do
expect(subject).to receive(:find_failed_project_registries).with('repository').and_call_original
it 'does not return registries where verification failed on secondary' do
# Verification failed on secondary
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
subject.count_failed_repositories
end
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)
it 'returns only project registries that repository sync has failed' do
expect(subject.find_failed_project_registries('repository')).to match_array([sync_failed, repository_sync_failed])
end
expect(subject.find_registries_to_verify(batch_size: 100)).to be_empty
end
end
it 'returns only project registries that wiki sync has failed' do
expect(subject.find_failed_project_registries('wiki')).to match_array([sync_failed, wiki_sync_failed])
end
# 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
skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo::Fdw.enabled?
end
context 'with selective sync' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
describe '#fdw_find_enabled_wikis' do
it 'does not count disabled wikis' do
expect(subject).to receive(:fdw_find_enabled_wikis).and_call_original
it 'delegates to #legacy_find_filtered_failed_projects' do
expect(subject).to receive(:legacy_find_filtered_failed_projects).and_call_original
create(:geo_project_registry, :synced, project: project_synced)
create(:geo_project_registry, :synced, project: create(:project, :wiki_disabled))
subject.find_failed_project_registries
end
expect(subject.count_synced_wikis).to eq 1
end
it 'returns project registries that sync has failed' do
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
project_synced.project_feature.update!(wiki_access_level: nil)
it 'returns only project registries that repository sync has failed' do
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
describe '#fdw_find_verified_wikis' do
it 'does not count disabled wikis' do
expect(subject).to receive(:fdw_find_verified_wikis).and_call_original
create(:geo_project_registry, :wiki_verified, project: project_wiki_verified)
create(:geo_project_registry, :wiki_verified, project: create(:project, :wiki_disabled))
describe '#find_registries_to_verify' do
it 'delegates to the correct method' do
expect(subject).to receive("#{method_prefix}_find_registries_to_verify".to_sym).and_call_original
expect(subject.count_verified_wikis).to eq 1
subject.find_registries_to_verify(batch_size: 10)
end
end
describe '#find_unsynced_projects' do
it 'delegates to #fdw_find_unsynced_projects' do
expect(subject).to receive(:fdw_find_unsynced_projects).and_call_original
it 'does not return registries that are verified on primary and secondary' do
project_verified = create(:repository_state, :repository_verified, :wiki_verified).project
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
it 'delegates to #legacy_find_unsynced_projects when node has selective sync' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
it 'does not return registries that were unverified/outdated on primary' do
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
it 'returns projects without an entry on the tracking database' do
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
it 'returns registries that were unverified/outdated on secondary' do
# 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(projects.first.id).to eq(project_not_synced.id)
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
end
describe '#find_projects_updated_recently' do
it 'delegates to #fdw_find_projects_updated_recently' do
expect(subject).to receive(:fdw_find_projects_updated_recently).and_call_original
it 'does not return registries that failed on primary' do
verification_failed_primary = create(:repository_state, :repository_failed, :wiki_failed).project
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
it 'delegates to #legacy_find_projects_updated_recently when node has selective sync' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
it 'returns registries where one failed and one verified on the primary' do
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
it 'returns projects with a dirty entry on the tracking database' do
project_repository_dirty = create(:project)
project_wiki_dirty = create(:project)
create(:geo_project_registry, :synced, :repository_dirty, project: project_repository_dirty)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_wiki_dirty)
it 'does not return registries where verification failed on secondary' do
# Verification failed on secondary
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
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
describe '#find_registries_to_verify' do
include_examples 'find outdated registries for repositories/wikis'
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
allow(Gitlab::Geo::Fdw).to receive(:enabled?).and_return(false)
skip('FDW is not configured') if Gitlab::Database.postgresql? && !Gitlab::Geo::Fdw.enabled?
end
describe '#find_unsynced_projects' do
it 'delegates to #legacy_find_unsynced_projects' do
expect(subject).to receive(:legacy_find_unsynced_projects).and_call_original
include_examples 'counts all the things'
subject.find_unsynced_projects(batch_size: 10)
end
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
include_examples 'finds all the things' do
let(:method_prefix) { 'fdw' }
end
end
describe '#find_projects_updated_recently' do
it 'delegates to #legacy_find_projects_updated_recently' do
expect(subject).to receive(:legacy_find_projects_updated_recently).and_call_original
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
context 'Legacy' do
before do
allow(Gitlab::Geo::Fdw).to receive(:enabled?).and_return(false)
end
describe '#find_registries_to_verify' do
include_examples 'find outdated registries for repositories/wikis'
include_examples 'counts all the things'
include_examples 'finds all the things' do
let(:method_prefix) { 'legacy' }
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