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

Refactor spec for Geo::AttachmentRegistryFinder

Since we made Foreign Data Wrapper (FDW) a hard requirement for
Geo on GitLab 12.0 we don't need to test the scenarios when the
feature flag is disabled.
parent 8e41caa7
...@@ -4,9 +4,9 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -4,9 +4,9 @@ describe Geo::AttachmentRegistryFinder, :geo 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 using the :delete DatabaseCleaner strategy, which is required for FDW # when using the :delete DatabaseCleaner strategy, which is required
# tests because a foreign table can't see changes inside a transaction of a # for FDW tests because a foreign table can't see changes inside a
# different connection. # transaction of a different connection.
let(:secondary) { create(:geo_node) } let(:secondary) { create(:geo_node) }
let(:synced_group) { create(:group) } let(:synced_group) { create(:group) }
...@@ -129,21 +129,30 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -129,21 +129,30 @@ describe Geo::AttachmentRegistryFinder, :geo do
end end
shared_examples 'counts all the things' do shared_examples 'counts all the things' do
describe '#count_syncable' do describe '#count_synced' do
let!(:upload_1) { create(:upload, model: synced_group) } let!(:upload_1) { create(:upload, model: synced_group) }
let!(:upload_2) { create(:upload, model: unsynced_group) } let!(:upload_2) { create(:upload, model: unsynced_group) }
let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) } let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) }
let!(:upload_4) { create(:upload, model: unsynced_project) } let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, :personal_snippet_upload) } let!(:upload_5) { create(:upload, :personal_snippet_upload) }
let(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
it 'counts attachments' do it 'counts attachments that have been synced' do
expect(subject.count_syncable).to eq 5 create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_synced).to eq 4
end end
it 'ignores remote attachments' do it 'ignores remote attachments' do
upload_1.update!(store: ObjectStorage::Store::REMOTE) create(:geo_file_registry, :attachment, file_id: upload_remote_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
expect(subject.count_syncable).to eq 4 expect(subject.count_synced).to eq 2
end end
context 'with selective sync by namespace' do context 'with selective sync by namespace' do
...@@ -151,14 +160,22 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -151,14 +160,22 @@ describe Geo::AttachmentRegistryFinder, :geo do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
it 'counts attachments' do it 'counts attachments that has been synced' do
expect(subject.count_syncable).to eq 3 create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_synced).to eq 2
end end
it 'ignores remote attachments' do it 'ignores remote attachments' do
upload_1.update!(store: ObjectStorage::Store::REMOTE) create(:geo_file_registry, :attachment, file_id: upload_remote_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
expect(subject.count_syncable).to eq 2 expect(subject.count_synced).to eq 1
end end
end end
...@@ -167,19 +184,27 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -167,19 +184,27 @@ describe Geo::AttachmentRegistryFinder, :geo do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end end
it 'counts attachments' do it 'counts attachments that has been synced' do
expect(subject.count_syncable).to eq 3 create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_synced).to eq 3
end end
it 'ignores remote attachments' do it 'ignores remote attachments' do
upload_4.update!(store: ObjectStorage::Store::REMOTE) create(:geo_file_registry, :attachment, file_id: upload_remote_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
expect(subject.count_syncable).to eq 2 expect(subject.count_synced).to eq 1
end end
end end
end end
describe '#count_registry' do describe '#count_failed' do
let!(:upload_1) { create(:upload, model: synced_group) } let!(:upload_1) { create(:upload, model: synced_group) }
let!(:upload_2) { create(:upload, model: unsynced_group) } let!(:upload_2) { create(:upload, model: unsynced_group) }
let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) } let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) }
...@@ -187,179 +212,61 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -187,179 +212,61 @@ describe Geo::AttachmentRegistryFinder, :geo do
let!(:upload_5) { create(:upload, :personal_snippet_upload) } let!(:upload_5) { create(:upload, :personal_snippet_upload) }
let(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) } let(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
it 'counts file registries for attachments' do it 'counts attachments that sync has failed' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true) create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id, missing_on_primary: false) create(:geo_file_registry, :attachment, :failed, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_5.id)
expect(subject.count_registry).to eq 5 expect(subject.count_failed).to eq 4
end end
context 'with selective sync by namespace' do it 'ignores remote attachments' do
before do create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
end create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
it 'does not apply the selective sync restriction' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true)
expect(subject.count_registry).to eq 5 expect(subject.count_failed).to eq 2
end
end end
context 'with selective sync by shard' do context 'with selective sync by namespace' do
before do before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'does not apply the selective sync restriction' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_registry).to eq 5
end end
end
end
end
it 'responds to file registry finder methods' do
file_registry_finder_methods = %i{
syncable
count_syncable
count_synced
count_failed
count_synced_missing_on_primary
count_registry
find_unsynced
find_migrated_local
find_retryable_failed_registries
find_retryable_synced_missing_on_primary_registries
}
file_registry_finder_methods.each do |method| it 'counts attachments that sync has failed' do
expect(subject).to respond_to(method) create(:geo_file_registry, :attachment, file_id: upload_1.id)
end create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
end create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_4.id)
# Disable transactions via :delete method because a foreign table create(:geo_file_registry, :attachment, :failed, file_id: upload_5.id)
# can't see changes inside a transaction of a different connection.
context 'FDW', :geo_fdw, :delete do
context 'with use_fdw_queries_for_selective_sync disabled' do
before do
stub_feature_flags(use_fdw_queries_for_selective_sync: false)
end
include_examples 'counts all the things'
include_examples 'finds all the things'
end
context 'with use_fdw_queries_for_selective_sync enabled' do
before do
stub_feature_flags(use_fdw_queries_for_selective_sync: true)
end
include_examples 'counts all the things'
describe '#count_synced' do
let!(:upload_1) { create(:upload, model: synced_group) }
let!(:upload_2) { create(:upload, model: unsynced_group) }
let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) }
let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, :personal_snippet_upload) }
let(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
it 'counts attachments that have been synced' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_synced).to eq 4 expect(subject.count_failed).to eq 2
end end
it 'ignores remote attachments' do it 'ignores remote attachments' do
create(:geo_file_registry, :attachment, file_id: upload_remote_1.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
expect(subject.count_synced).to eq 2
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts attachments that has been synced' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_synced).to eq 2
end
it 'ignores remote attachments' do
create(:geo_file_registry, :attachment, file_id: upload_remote_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
expect(subject.count_synced).to eq 1
end
end
context 'with selective sync by shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'counts attachments that has been synced' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_synced).to eq 3
end
it 'ignores remote attachments' do
create(:geo_file_registry, :attachment, file_id: upload_remote_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id)
create(:geo_file_registry, :attachment, file_id: upload_3.id)
expect(subject.count_synced).to eq 1 expect(subject.count_failed).to eq 1
end
end end
end end
describe '#count_failed' do context 'with selective sync by shard' do
let!(:upload_1) { create(:upload, model: synced_group) } before do
let!(:upload_2) { create(:upload, model: unsynced_group) } secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) } end
let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, :personal_snippet_upload) }
let(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
it 'counts attachments that sync has failed' do it 'counts attachments that sync has failed' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id) create(:geo_file_registry, :attachment, file_id: upload_1.id)
create(:geo_file_registry, :attachment, file_id: upload_2.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_4.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_4.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_5.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_5.id)
expect(subject.count_failed).to eq 4 expect(subject.count_failed).to eq 3
end end
it 'ignores remote attachments' do it 'ignores remote attachments' do
...@@ -367,71 +274,71 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -367,71 +274,71 @@ describe Geo::AttachmentRegistryFinder, :geo do
create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id) create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
expect(subject.count_failed).to eq 2 expect(subject.count_failed).to eq 1
end end
end
end
describe '#count_synced_missing_on_primary' do
let!(:upload_1) { create(:upload, model: synced_group) }
let!(:upload_2) { create(:upload, model: unsynced_group) }
let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) }
let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, :personal_snippet_upload) }
let(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
context 'with selective sync by namespace' do it 'counts attachments that have been synced and are missing on the primary' do
before do create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true)
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
end create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_4.id, missing_on_primary: false)
create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true)
it 'counts attachments that sync has failed' do expect(subject.count_synced_missing_on_primary).to eq 3
create(:geo_file_registry, :attachment, file_id: upload_1.id) end
create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_4.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_5.id)
expect(subject.count_failed).to eq 2 it 'ignores remote attachments' do
end create(:geo_file_registry, :attachment, file_id: upload_remote_1.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
it 'ignores remote attachments' do expect(subject.count_synced_missing_on_primary).to eq 2
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id) end
create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
expect(subject.count_failed).to eq 1 context 'with selective sync by namespace' do
end before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
context 'with selective sync by shard' do it 'counts attachments that have been synced and are missing on the primary' do
before do create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true)
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
end create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_4.id, missing_on_primary: true)
it 'counts attachments that sync has failed' do create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_1.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_4.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_5.id)
expect(subject.count_failed).to eq 3 expect(subject.count_synced_missing_on_primary).to eq 2
end end
it 'ignores remote attachments' do it 'ignores remote attachments' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id) create(:geo_file_registry, :attachment, file_id: upload_remote_1.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id) create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id) create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
expect(subject.count_failed).to eq 1 expect(subject.count_synced_missing_on_primary).to eq 1
end
end end
end end
describe '#count_synced_missing_on_primary' do context 'with selective sync by shard' do
let!(:upload_1) { create(:upload, model: synced_group) } before do
let!(:upload_2) { create(:upload, model: unsynced_group) } secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) } end
let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, :personal_snippet_upload) }
let(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
it 'counts attachments that have been synced and are missing on the primary' do it 'counts attachments that have been synced and are missing on the primary' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true) create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true) create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true) create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_4.id, missing_on_primary: false) create(:geo_file_registry, :attachment, file_id: upload_4.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true) create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 3 expect(subject.count_synced_missing_on_primary).to eq 3
...@@ -442,65 +349,59 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -442,65 +349,59 @@ describe Geo::AttachmentRegistryFinder, :geo do
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true) create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true) create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 2 expect(subject.count_synced_missing_on_primary).to eq 1
end end
end
end
context 'with selective sync by namespace' do describe '#count_syncable' do
before do let!(:upload_1) { create(:upload, model: synced_group) }
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group]) let!(:upload_2) { create(:upload, model: unsynced_group) }
end let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project_in_nested_group) }
let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, :personal_snippet_upload) }
it 'counts attachments that have been synced and are missing on the primary' do it 'counts attachments' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true) expect(subject.count_syncable).to eq 5
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true) end
create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_4.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 2 it 'ignores remote attachments' do
end upload_1.update!(store: ObjectStorage::Store::REMOTE)
it 'ignores remote attachments' do expect(subject.count_syncable).to eq 4
create(:geo_file_registry, :attachment, file_id: upload_remote_1.id, missing_on_primary: true) end
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 1 context 'with selective sync by namespace' do
end before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
context 'with selective sync by shard' do it 'counts attachments' do
before do expect(subject.count_syncable).to eq 3
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken']) end
end
it 'counts attachments that have been synced and are missing on the primary' do it 'ignores remote attachments' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true) upload_1.update!(store: ObjectStorage::Store::REMOTE)
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_4.id, missing_on_primary: true)
create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true)
expect(subject.count_synced_missing_on_primary).to eq 3 expect(subject.count_syncable).to eq 2
end end
end
it 'ignores remote attachments' do context 'with selective sync by shard' do
create(:geo_file_registry, :attachment, file_id: upload_remote_1.id, missing_on_primary: true) before do
create(:geo_file_registry, :attachment, file_id: upload_2.id, missing_on_primary: true) secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
create(:geo_file_registry, :attachment, file_id: upload_3.id, missing_on_primary: true) end
expect(subject.count_synced_missing_on_primary).to eq 1 it 'counts attachments' do
end expect(subject.count_syncable).to eq 3
end end
end
include_examples 'finds all the things' it 'ignores remote attachments' do
end upload_4.update!(store: ObjectStorage::Store::REMOTE)
end
context 'Legacy' do expect(subject.count_syncable).to eq 2
before do end
stub_fdw_disabled end
end end
describe '#count_registry' do describe '#count_registry' do
...@@ -554,4 +455,28 @@ describe Geo::AttachmentRegistryFinder, :geo do ...@@ -554,4 +455,28 @@ describe Geo::AttachmentRegistryFinder, :geo do
end end
end end
end end
it 'responds to file registry finder methods' do
file_registry_finder_methods = %i{
syncable
count_syncable
count_synced
count_failed
count_synced_missing_on_primary
count_registry
find_unsynced
find_migrated_local
find_retryable_failed_registries
find_retryable_synced_missing_on_primary_registries
}
file_registry_finder_methods.each do |method|
expect(subject).to respond_to(method)
end
end
context 'FDW', :geo_fdw do
include_examples 'counts all the things'
include_examples 'finds all the things'
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