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
include ::EE::GeoHelpers
# Using let() instead of set() because set() does not work properly
# when using the :delete DatabaseCleaner strategy, which is required for FDW
# tests because a foreign table can't see changes inside a transaction of a
# different connection.
# when using the :delete DatabaseCleaner strategy, which is required
# for FDW tests because a foreign table can't see changes inside a
# transaction of a different connection.
let(:secondary) { create(:geo_node) }
let(:synced_group) { create(:group) }
......@@ -129,21 +129,30 @@ describe Geo::AttachmentRegistryFinder, :geo do
end
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_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' do
expect(subject.count_syncable).to eq 5
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
end
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
context 'with selective sync by namespace' do
......@@ -151,14 +160,22 @@ describe Geo::AttachmentRegistryFinder, :geo do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts attachments' do
expect(subject.count_syncable).to eq 3
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
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
......@@ -167,19 +184,27 @@ describe Geo::AttachmentRegistryFinder, :geo do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'counts attachments' do
expect(subject.count_syncable).to eq 3
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
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
describe '#count_registry' do
describe '#count_failed' 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) }
......@@ -187,179 +212,61 @@ describe Geo::AttachmentRegistryFinder, :geo do
let!(:upload_5) { create(:upload, :personal_snippet_upload) }
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, 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, missing_on_primary: false)
create(:geo_file_registry, :attachment, file_id: upload_5.id)
create(:geo_file_registry, :attachment, 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_registry).to eq 5
expect(subject.count_failed).to eq 4
end
context 'with selective sync by namespace' do
before do
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, 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)
it 'ignores remote attachments' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id)
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_registry).to eq 5
end
expect(subject.count_failed).to eq 2
end
context 'with selective sync by shard' do
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
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
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
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
# Disable transactions via :delete method because a foreign table
# 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)
it 'counts attachments that sync has failed' do
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_synced).to eq 4
expect(subject.count_failed).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 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)
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id)
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_synced).to eq 1
end
expect(subject.count_failed).to eq 1
end
end
describe '#count_failed' 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 shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
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_2.id)
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 4
expect(subject.count_failed).to eq 3
end
it 'ignores remote attachments' 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_3.id)
expect(subject.count_failed).to eq 2
expect(subject.count_failed).to eq 1
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
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
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, 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: false)
create(:geo_file_registry, :attachment, file_id: upload_5.id, missing_on_primary: true)
it 'counts attachments that sync has failed' do
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_synced_missing_on_primary).to eq 3
end
expect(subject.count_failed).to eq 2
end
it 'ignores remote attachments' do
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
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id)
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_synced_missing_on_primary).to eq 2
end
expect(subject.count_failed).to eq 1
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
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 sync has failed' do
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)
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, 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_failed).to eq 3
end
expect(subject.count_synced_missing_on_primary).to eq 2
end
it 'ignores remote attachments' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_2.id)
create(:geo_file_registry, :attachment, :failed, file_id: upload_3.id)
it 'ignores remote attachments' do
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)
expect(subject.count_failed).to eq 1
end
expect(subject.count_synced_missing_on_primary).to eq 1
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 shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
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, 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: 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)
expect(subject.count_synced_missing_on_primary).to eq 3
......@@ -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_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
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
describe '#count_syncable' 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) }
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, 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)
it 'counts attachments' do
expect(subject.count_syncable).to eq 5
end
expect(subject.count_synced_missing_on_primary).to eq 2
end
it 'ignores remote attachments' do
upload_1.update!(store: ObjectStorage::Store::REMOTE)
it 'ignores remote attachments' do
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)
expect(subject.count_syncable).to eq 4
end
expect(subject.count_synced_missing_on_primary).to eq 1
end
context 'with selective sync by namespace' do
before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
context 'with selective sync by shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'counts attachments' do
expect(subject.count_syncable).to eq 3
end
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, 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)
it 'ignores remote attachments' do
upload_1.update!(store: ObjectStorage::Store::REMOTE)
expect(subject.count_synced_missing_on_primary).to eq 3
end
expect(subject.count_syncable).to eq 2
end
end
it 'ignores remote attachments' do
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)
context 'with selective sync by shard' do
before do
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
expect(subject.count_synced_missing_on_primary).to eq 1
end
it 'counts attachments' do
expect(subject.count_syncable).to eq 3
end
end
include_examples 'finds all the things'
end
end
it 'ignores remote attachments' do
upload_4.update!(store: ObjectStorage::Store::REMOTE)
context 'Legacy' do
before do
stub_fdw_disabled
expect(subject.count_syncable).to eq 2
end
end
end
describe '#count_registry' do
......@@ -554,4 +455,28 @@ describe Geo::AttachmentRegistryFinder, :geo do
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
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