Commit 0adc0efe authored by Douglas Barbosa Alexandre's avatar Douglas Barbosa Alexandre Committed by Ash McKenzie

Refactor spec for Geo::ProjectRegistryFinder

parent bdfa544a
require 'spec_helper' require 'spec_helper'
describe Geo::ProjectRegistryFinder, :geo do describe Geo::ProjectRegistryFinder, :geo, :geo_fdw do
include ::EE::GeoHelpers include ::EE::GeoHelpers
# Using let() instead of set() because set() does not work properly # Using let() instead of set() because set() does not work properly when
# when using the :delete DatabaseCleaner strategy, which is required for FDW # using the :delete DatabaseCleaner strategy, which is required for FDW
# tests because a foreign table can't see changes inside a transaction of a # tests because a foreign table can't see changes inside a transaction
# different connection. # of a different connection.
let(:secondary) { create(:geo_node) } let(:secondary) { create(:geo_node) }
let(:synced_group) { create(:group) }
let(:nested_group_1) { create(:group, parent: synced_group) }
let(:project) { create(:project) }
let(:project_1_in_synced_group) { create(:project, group: synced_group) }
let(:project_2_in_synced_group) { create(:project, group: nested_group_1) }
let(:project_3_in_synced_group) { create(:project, group: synced_group) }
let(:project_4_broken_storage) { create(:project, :broken_storage) }
subject { described_class.new(current_node: secondary) } subject { described_class.new(current_node: secondary) }
...@@ -22,381 +15,175 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -22,381 +15,175 @@ describe Geo::ProjectRegistryFinder, :geo do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
end end
shared_examples 'counts all the things' do describe '#count_synced_repositories' do
describe '#count_synced_repositories' do it 'delegates to the proper finder' do
before do expect_next_instance_of(Geo::ProjectRegistrySyncedFinder) do |finder|
create(:geo_project_registry, :synced, project: project) expect(finder).to receive(:execute).once.and_call_original
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, :sync_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_4_broken_storage)
end
it 'counts registries that repository have been synced' do
expect(subject.count_synced_repositories).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that repository have been synced where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_synced_repositories).to eq 1
end
end end
context 'with selective sync by shard' do subject.count_synced_repositories
it 'counts registries that repository have been synced where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_synced_repositories).to eq 1
end
end
end end
describe '#count_synced_wikis' do it 'returns an integer' do
before do expect(subject.count_synced_repositories).to be_a(Integer)
create(:geo_project_registry, :synced, project: project)
create(:geo_project_registry, :synced, :wiki_dirty, project: project_1_in_synced_group)
create(:geo_project_registry, :synced, :repository_dirty, project: project_2_in_synced_group)
create(:geo_project_registry, :sync_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :synced, :repository_dirty, project: project_4_broken_storage)
end
it 'counts registries that wiki have been synced' do
expect(subject.count_synced_wikis).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that wiki have been synced where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_synced_wikis).to eq 1
end
end
context 'with selective sync by shard' do
it 'counts registries that wiki have been synced where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_synced_wikis).to eq 1
end
end
end end
end
describe '#count_failed_repositories' do describe '#count_synced_wikis' do
before do it 'delegates to the proper finder' do
create(:geo_project_registry, :synced, project: project) expect_next_instance_of(Geo::ProjectRegistrySyncedFinder) do |finder|
create(:geo_project_registry, :repository_sync_failed, project: project_1_in_synced_group) expect(finder).to receive(:execute).once.and_call_original
create(:geo_project_registry, :wiki_sync_failed, project: project_2_in_synced_group)
create(:geo_project_registry, :sync_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :repository_sync_failed, project: project_4_broken_storage)
end
it 'counts registries that repository sync has failed' do
expect(subject.count_failed_repositories).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that repository sync has failed where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_failed_repositories).to eq 2
end
end end
context 'with selective sync by shard' do subject.count_synced_wikis
it 'counts registries that repository sync has failed where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_failed_repositories).to eq 1
end
end
end end
describe '#count_failed_wikis' do it 'returns an integer' do
before do expect(subject.count_synced_wikis).to be_a(Integer)
create(:geo_project_registry, :synced, project: project)
create(:geo_project_registry, :wiki_sync_failed, project: project_1_in_synced_group)
create(:geo_project_registry, :repository_sync_failed, project: project_2_in_synced_group)
create(:geo_project_registry, :sync_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :wiki_sync_failed, project: project_4_broken_storage)
end
it 'counts registries that wiki sync has failed' do
expect(subject.count_failed_wikis).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that wiki sync has failed where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_failed_wikis).to eq 2
end
end
context 'with selective sync by shard' do
it 'counts registries that wiki sync has failed where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_failed_wikis).to eq 1
end
end
end end
end
describe '#count_verified_repositories' do describe '#count_failed_repositories' do
before do it 'delegates to the proper finder' do
create(:geo_project_registry, :repository_verified, :wiki_verified, project: project) expect_next_instance_of(Geo::ProjectRegistrySyncFailedFinder) do |finder|
create(:geo_project_registry, :repository_verified, project: project_1_in_synced_group) expect(finder).to receive(:execute).once.and_call_original
create(:geo_project_registry, :repository_verification_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :repository_verified, project: project_4_broken_storage)
create(:geo_project_registry, :wiki_verified, project: project_2_in_synced_group)
end
it 'counts registries that repository have beend verified' do
expect(subject.count_verified_repositories).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that repository have beend verified where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_verified_repositories).to eq 1
end
end end
context 'with selective sync by shard' do subject.count_failed_repositories
it 'counts registries that repository have beend verified where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_verified_repositories).to eq 1
end
end
end end
describe '#count_verified_wikis' do it 'returns an integer' do
before do expect(subject.count_failed_repositories).to be_a(Integer)
create(:geo_project_registry, :wiki_verified, :wiki_verified, project: project)
create(:geo_project_registry, :wiki_verified, project: project_1_in_synced_group)
create(:geo_project_registry, :wiki_verification_failed, project: project_3_in_synced_group)
create(:geo_project_registry, :wiki_verified, project: project_4_broken_storage)
create(:geo_project_registry, :repository_verified, project: project_2_in_synced_group)
end
it 'counts registries that wiki have beend verified' do
expect(subject.count_verified_wikis).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that wiki have beend verified where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_verified_wikis).to eq 1
end
end
context 'with selective sync by shard' do
it 'counts registries that wiki have beend verified where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_verified_wikis).to eq 1
end
end
end end
end
describe '#count_verification_failed_repositories' do describe '#count_failed_wikis' do
before do it 'delegates to the proper finder' do
create(:geo_project_registry, :repository_verification_failed, :wiki_verification_failed, project: project) expect_next_instance_of(Geo::ProjectRegistrySyncFailedFinder) do |finder|
create(:geo_project_registry, :repository_verification_failed, project: project_1_in_synced_group) expect(finder).to receive(:execute).once.and_call_original
create(:geo_project_registry, :repository_verification_failed, project: project_4_broken_storage)
create(:geo_project_registry, :wiki_verification_failed, project: project_2_in_synced_group)
end
it 'counts registries that repository verification has failed' do
expect(subject.count_verification_failed_repositories).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that repository verification has failed where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_verification_failed_repositories).to eq 1
end
end end
context 'with selective sync by shard' do subject.count_failed_wikis
it 'counts registries that repository verification has failed where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_verification_failed_repositories).to eq 1
end
end
end end
describe '#count_verification_failed_wikis' do it 'returns an integer' do
before do expect(subject.count_failed_wikis).to be_a(Integer)
create(:geo_project_registry, :repository_verification_failed, :wiki_verification_failed, project: project)
create(:geo_project_registry, :wiki_verification_failed, project: project_1_in_synced_group)
create(:geo_project_registry, :wiki_verification_failed, project: project_4_broken_storage)
create(:geo_project_registry, :repository_verification_failed, project: project_2_in_synced_group)
end
it 'counts registries that wiki verification has failed' do
expect(subject.count_verification_failed_wikis).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that wiki verification has failed where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_verification_failed_wikis).to eq 1
end
end
context 'with selective sync by shard' do
it 'counts registries that wiki verification has failed where projects belongs to the shards' do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_verification_failed_wikis).to eq 1
end
end
end end
end
describe '#count_repositories_retrying_verification' do describe '#count_verified_repositories' do
before do it 'delegates to the proper finder' do
create(:geo_project_registry, :repository_retrying_verification, :wiki_retrying_verification, project: project) expect_next_instance_of(Geo::ProjectRegistryVerifiedFinder) do |finder|
create(:geo_project_registry, :repository_retrying_verification, project: project_1_in_synced_group) expect(finder).to receive(:execute).once.and_call_original
create(:geo_project_registry, :repository_retrying_verification, project: project_4_broken_storage)
create(:geo_project_registry, :wiki_retrying_verification, project: project_2_in_synced_group)
end
it 'counts registries that repository retrying verification' do
expect(subject.count_repositories_retrying_verification).to eq 3
end
context 'with selective sync by namespace' do
it 'counts registries that repository retrying verification where projects belongs to the namespaces' do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(subject.count_repositories_retrying_verification).to eq 1
end
end end
context 'with selective sync by shard' do subject.count_verified_repositories
it 'counts registries that repository retrying verification where projects belongs to the shards' do end
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_repositories_retrying_verification).to eq 1 it 'returns an integer' do
end expect(subject.count_verified_repositories).to be_a(Integer)
end
end end
end
describe '#count_wikis_retrying_verification' do describe '#count_verified_wikis' do
before do it 'delegates to the proper finder' do
create(:geo_project_registry, :repository_retrying_verification, :wiki_retrying_verification, project: project) expect_next_instance_of(Geo::ProjectRegistryVerifiedFinder) do |finder|
create(:geo_project_registry, :repository_retrying_verification, project: project_1_in_synced_group) expect(finder).to receive(:execute).once.and_call_original
create(:geo_project_registry, :wiki_retrying_verification, project: project_2_in_synced_group)
create(:geo_project_registry, :wiki_retrying_verification, project: project_4_broken_storage)
end end
it 'counts registries that wiki retrying verification' do subject.count_verified_wikis
expect(subject.count_wikis_retrying_verification).to eq 3 end
end
context 'with selective sync by namespace' do it 'returns an integer' do
it 'counts registries that wiki retrying verification where projects belongs to the namespaces' do expect(subject.count_verified_wikis).to be_a(Integer)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) end
end
expect(subject.count_wikis_retrying_verification).to eq 1 describe '#count_verification_failed_repositories' do
end it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistryVerificationFailedFinder) do |finder|
expect(finder).to receive(:execute).once.and_call_original
end end
context 'with selective sync by shard' do subject.count_verification_failed_repositories
it 'counts registries that wiki retrying verification where projects belongs to the shards' do end
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_wikis_retrying_verification).to eq 1 it 'returns an integer' do
end expect(subject.count_verification_failed_repositories).to be_a(Integer)
end
end end
end
describe '#count_repositories_checksum_mismatch' do describe '#count_verification_failed_wikis' do
before do it 'delegates to the proper finder' do
create(:geo_project_registry, :repository_checksum_mismatch, :wiki_checksum_mismatch, project: project) expect_next_instance_of(Geo::ProjectRegistryVerificationFailedFinder) do |finder|
create(:geo_project_registry, :repository_checksum_mismatch, project: project_1_in_synced_group) expect(finder).to receive(:execute).once.and_call_original
create(:geo_project_registry, :repository_checksum_mismatch, :wiki_verified, project: project_4_broken_storage)
create(:geo_project_registry, :wiki_checksum_mismatch, project: project_2_in_synced_group)
end end
it 'counts registries that repository mismatch' do subject.count_verification_failed_wikis
expect(subject.count_repositories_checksum_mismatch).to eq 3 end
end
context 'with selective sync by namespace' do it 'returns an integer' do
it 'counts mismatch registries where projects belongs to the namespaces' do expect(subject.count_verification_failed_wikis).to be_a(Integer)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) end
end
expect(subject.count_repositories_checksum_mismatch).to eq 1 describe '#count_repositories_retrying_verification' do
end it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistryRetryingVerificationFinder) do |finder|
expect(finder).to receive(:execute).once.and_call_original
end end
context 'with selective sync by shard' do subject.count_repositories_retrying_verification
it 'counts mismatch registries where projects belongs to the shards' do end
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_repositories_checksum_mismatch).to eq 1 it 'returns an integer' do
end expect(subject.count_repositories_retrying_verification).to be_a(Integer)
end
end end
end
describe '#count_wikis_checksum_mismatch' do describe '#count_wikis_retrying_verification' do
before do it 'delegates to the proper finder' do
create(:geo_project_registry, :repository_checksum_mismatch, :wiki_checksum_mismatch, project: project) expect_next_instance_of(Geo::ProjectRegistryRetryingVerificationFinder) do |finder|
create(:geo_project_registry, :repository_checksum_mismatch, project: project_1_in_synced_group) expect(finder).to receive(:execute).once.and_call_original
create(:geo_project_registry, :wiki_checksum_mismatch, project: project_2_in_synced_group)
create(:geo_project_registry, :repository_verified, :wiki_checksum_mismatch, project: project_4_broken_storage)
end end
it 'counts registries that wiki mismatch' do subject.count_wikis_retrying_verification
expect(subject.count_wikis_checksum_mismatch).to eq 3 end
end
context 'with selective sync by namespace' do it 'returns an integer' do
it 'counts mismatch registries where projects belongs to the namespaces' do expect(subject.count_wikis_retrying_verification).to be_a(Integer)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) end
end
expect(subject.count_wikis_checksum_mismatch).to eq 1 describe '#count_repositories_checksum_mismatch' do
end it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistryMismatchFinder) do |finder|
expect(finder).to receive(:execute).once.and_call_original
end end
context 'with selective sync by shard' do subject.count_repositories_checksum_mismatch
it 'counts mismatch registries where projects belongs to the shards' do end
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
expect(subject.count_wikis_checksum_mismatch).to eq 1 it 'returns an integer' do
end expect(subject.count_repositories_checksum_mismatch).to be_a(Integer)
end
end end
end end
context 'FDW', :geo_fdw do describe '#count_wikis_checksum_mismatch' do
context 'with use_fdw_queries_for_selective_sync disabled' do it 'delegates to the proper finder' do
before do expect_next_instance_of(Geo::ProjectRegistryMismatchFinder) do |finder|
stub_feature_flags(use_fdw_queries_for_selective_sync: false) expect(finder).to receive(:execute).once.and_call_original
end end
include_examples 'counts all the things' subject.count_wikis_checksum_mismatch
end end
context 'with use_fdw_queries_for_selective_sync enabled' do it 'returns an integer' do
before do expect(subject.count_wikis_checksum_mismatch).to be_a(Integer)
stub_feature_flags(use_fdw_queries_for_selective_sync: true)
end
include_examples 'counts all the things'
end end
end end
describe '#find_unsynced_projects', :geo_fdw do describe '#find_unsynced_projects' do
it 'delegates to the proper finder' do it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectUnsyncedFinder) do |finder| expect_next_instance_of(Geo::ProjectUnsyncedFinder) do |finder|
expect(finder).to receive(:execute).once expect(finder).to receive(:execute).once
...@@ -406,7 +193,7 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -406,7 +193,7 @@ describe Geo::ProjectRegistryFinder, :geo do
end end
end end
describe '#find_projects_updated_recently', :geo_fdw do describe '#find_projects_updated_recently' do
it 'delegates to the proper finder' do it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectUpdatedRecentlyFinder) do |finder| expect_next_instance_of(Geo::ProjectUpdatedRecentlyFinder) do |finder|
expect(finder).to receive(:execute).once expect(finder).to receive(:execute).once
...@@ -416,7 +203,7 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -416,7 +203,7 @@ describe Geo::ProjectRegistryFinder, :geo do
end end
end end
describe '#find_failed_project_registries', :geo_fdw do describe '#find_failed_project_registries' do
it 'delegates to the proper finder' do it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistrySyncFailedFinder) do |finder| expect_next_instance_of(Geo::ProjectRegistrySyncFailedFinder) do |finder|
expect(finder).to receive(:execute).once expect(finder).to receive(:execute).once
...@@ -426,7 +213,7 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -426,7 +213,7 @@ describe Geo::ProjectRegistryFinder, :geo do
end end
end end
describe '#find_registries_to_verify', :geo_fdw do describe '#find_registries_to_verify' do
it 'delegates to the proper finder' do it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistryPendingVerificationFinder) do |finder| expect_next_instance_of(Geo::ProjectRegistryPendingVerificationFinder) do |finder|
expect(finder).to receive(:execute).once expect(finder).to receive(:execute).once
...@@ -436,7 +223,7 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -436,7 +223,7 @@ describe Geo::ProjectRegistryFinder, :geo do
end end
end end
describe '#find_verification_failed_project_registries', :geo_fdw do describe '#find_verification_failed_project_registries' do
it 'delegates to the proper finder' do it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistryVerificationFailedFinder) do |finder| expect_next_instance_of(Geo::ProjectRegistryVerificationFailedFinder) do |finder|
expect(finder).to receive(:execute).once expect(finder).to receive(:execute).once
...@@ -446,7 +233,7 @@ describe Geo::ProjectRegistryFinder, :geo do ...@@ -446,7 +233,7 @@ describe Geo::ProjectRegistryFinder, :geo do
end end
end end
describe '#find_checksum_mismatch_project_registries', :geo_fdw do describe '#find_checksum_mismatch_project_registries' do
it 'delegates to the proper finder' do it 'delegates to the proper finder' do
expect_next_instance_of(Geo::ProjectRegistryMismatchFinder) do |finder| expect_next_instance_of(Geo::ProjectRegistryMismatchFinder) do |finder|
expect(finder).to receive(:execute).once expect(finder).to receive(:execute).once
......
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