Commit 55c46a9b authored by Mayra Cabrera's avatar Mayra Cabrera

Merge branch '10586-specs-refactor' into 'master'

Geo: refactor some specs

See merge request gitlab-org/gitlab-ee!14518
parents 516ef2ea 997952df
...@@ -16,20 +16,13 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -16,20 +16,13 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
let(:synced_project_in_nested_group) { create(:project, group: synced_subgroup) } let(:synced_project_in_nested_group) { create(:project, group: synced_subgroup) }
let(:unsynced_project) { create(:project, :broken_storage, group: unsynced_group) } let(:unsynced_project) { create(:project, :broken_storage, group: unsynced_group) }
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) }
let(:upload_4) { create(:upload, model: unsynced_project) }
let(:upload_5) { create(:upload, model: synced_project) }
subject { described_class.new(current_node_id: secondary.id) } subject { described_class.new(current_node_id: secondary.id) }
before do before do
stub_current_geo_node(secondary) stub_current_geo_node(secondary)
end end
shared_examples 'finds all the things' do context 'finds all the things' do
describe '#find_unsynced' 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) } let!(:upload_3) { create(:upload, :issuable_upload, model: synced_project) }
...@@ -37,22 +30,27 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -37,22 +30,27 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
let!(:upload_5) { create(:upload, model: synced_project) } let!(:upload_5) { create(:upload, model: synced_project) }
let!(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) } let!(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
it 'returns attachments without an entry on the tracking database' do describe '#find_unsynced' do
before do
create(:geo_file_registry, :avatar, file_id: upload_1.id) create(:geo_file_registry, :avatar, file_id: upload_1.id)
end
attachments = subject.find_unsynced(batch_size: 10, except_file_ids: [upload_2.id]) it 'returns attachments without an entry on the tracking database' do
attachments = subject.find_unsynced(batch_size: 10)
expect(attachments).to match_ids(upload_3, upload_4, upload_5) expect(attachments).to match_ids(upload_2, upload_3, upload_4, upload_5)
end end
context 'with selective sync by namespace' do it 'returns attachments without an entry on the tracking database, excluding from exception list' do
before do attachments = subject.find_unsynced(batch_size: 10, except_file_ids: [upload_2.id, upload_3.id])
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
expect(attachments).to match_ids(upload_4, upload_5)
end end
it 'returns attachments without an entry on the tracking database' do context 'with selective sync by namespace' do
create(:geo_file_registry, :avatar, file_id: upload_1.id) let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
it 'returns attachments without an entry on the tracking database, excluding from exception list' do
attachments = subject.find_unsynced(batch_size: 10, except_file_ids: [upload_5.id]) attachments = subject.find_unsynced(batch_size: 10, except_file_ids: [upload_5.id])
expect(attachments).to match_ids(upload_3) expect(attachments).to match_ids(upload_3)
...@@ -60,9 +58,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -60,9 +58,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
context 'with selective sync by shard' do context 'with selective sync by shard' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'returns attachments without an entry on the tracking database' do it 'returns attachments without an entry on the tracking database' do
create(:geo_file_registry, :avatar, file_id: upload_2.id) create(:geo_file_registry, :avatar, file_id: upload_2.id)
...@@ -75,12 +71,6 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -75,12 +71,6 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
describe '#find_migrated_local' do describe '#find_migrated_local' 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) }
let!(:upload_4) { create(:upload, model: unsynced_project) }
let!(:upload_5) { create(:upload, model: synced_project) }
let!(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
let!(:upload_remote_2) { create(:upload, :object_storage, model: unsynced_project) } let!(:upload_remote_2) { create(:upload, :object_storage, model: unsynced_project) }
before do before do
...@@ -103,9 +93,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -103,9 +93,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
context 'with selective sync by namespace' do context 'with selective sync by namespace' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'returns attachments stored remotely and successfully synced locally' do it 'returns attachments stored remotely and successfully synced locally' do
attachments = subject.find_migrated_local(batch_size: 10) attachments = subject.find_migrated_local(batch_size: 10)
...@@ -115,9 +103,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -115,9 +103,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
context 'with selective sync by shard' do context 'with selective sync by shard' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'returns attachments stored remotely and successfully synced locally' do it 'returns attachments stored remotely and successfully synced locally' do
attachments = subject.find_migrated_local(batch_size: 10) attachments = subject.find_migrated_local(batch_size: 10)
...@@ -128,239 +114,108 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -128,239 +114,108 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
end end
shared_examples 'counts all the things' do context 'counts all the things' 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) } let!(:upload_remote_1) { create(:upload, :object_storage, model: synced_project) }
it 'counts attachments that have been synced' do describe '#count_synced' do
before 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) 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_3.id)
create(:geo_file_registry, :attachment, file_id: upload_4.id) create(:geo_file_registry, :attachment, file_id: upload_4.id)
create(:geo_file_registry, :attachment, file_id: upload_5.id) create(:geo_file_registry, :attachment, file_id: upload_5.id)
expect(subject.count_synced).to eq 4
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_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 end
context 'with selective sync by namespace' do it 'counts attachments that have been synced and ignore remote attachments' do
before do expect(subject.count_synced).to eq 4
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
it 'counts attachments that has been synced' do context 'with selective sync by namespace' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id) let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
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 has been synced and ignore remote attachments' do
expect(subject.count_synced).to eq 2 expect(subject.count_synced).to eq 2
end 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 end
context 'with selective sync by shard' do context 'with selective sync by shard' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
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)
it 'counts attachments that has been synced and ignores remote attachments' do
expect(subject.count_synced).to eq 3 expect(subject.count_synced).to eq 3
end 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 end
end end
describe '#count_failed' 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) }
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
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, :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
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)
expect(subject.count_failed).to eq 2
end
context 'with selective sync by namespace' do
before do before do
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts attachments that sync has failed' do
create(:geo_file_registry, :attachment, file_id: upload_1.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_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)
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id)
end
expect(subject.count_failed).to eq 2 it 'counts attachments that sync has failed and ignores remote attachments' do
expect(subject.count_failed).to eq 4
end end
it 'ignores remote attachments' do context 'with selective sync by namespace' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_remote_1.id) let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
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 it 'counts attachments that sync has failed and ignores remote attachments' do
expect(subject.count_failed).to eq 2
end end
end end
context 'with selective sync by shard' do context 'with selective sync by shard' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
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 sync has failed and ignores remote attachments' do
expect(subject.count_failed).to eq 3 expect(subject.count_failed).to eq 3
end 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)
expect(subject.count_failed).to eq 1
end
end end
end end
describe '#count_synced_missing_on_primary' do describe '#count_synced_missing_on_primary' do
let!(:upload_1) { create(:upload, model: synced_group) } before do
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 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: false)
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
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_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_synced_missing_on_primary).to eq 2
end end
context 'with selective sync by namespace' do it 'counts attachments that have been synced, are missing on the primary, ignoring remote attachments' do
before do expect(subject.count_synced_missing_on_primary).to eq 3
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end end
it 'counts attachments that have been synced and are missing on the primary' do context 'with selective sync by namespace' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true) let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
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 that have been synced, are missing on the primary, ignoring remote attachments' do
expect(subject.count_synced_missing_on_primary).to eq 2 expect(subject.count_synced_missing_on_primary).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)
expect(subject.count_synced_missing_on_primary).to eq 1
end
end end
context 'with selective sync by shard' do context 'with selective sync by shard' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
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 it 'counts attachments that have been synced, are missing on the primary, ignoring remote attachments' do
create(:geo_file_registry, :attachment, :failed, file_id: upload_1.id, missing_on_primary: true) expect(subject.count_synced_missing_on_primary).to eq 2
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
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)
expect(subject.count_synced_missing_on_primary).to eq 1
end end
end end
end end
describe '#count_syncable' do 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' do it 'counts attachments' do
expect(subject.count_syncable).to eq 5 expect(subject.count_syncable).to eq 5
end end
...@@ -372,9 +227,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -372,9 +227,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
context 'with selective sync by namespace' do context 'with selective sync by namespace' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'counts attachments' do it 'counts attachments' do
expect(subject.count_syncable).to eq 3 expect(subject.count_syncable).to eq 3
...@@ -388,9 +241,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -388,9 +241,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
context 'with selective sync by shard' do context 'with selective sync by shard' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'counts attachments' do it 'counts attachments' do
expect(subject.count_syncable).to eq 3 expect(subject.count_syncable).to eq 3
...@@ -405,13 +256,6 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -405,13 +256,6 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
describe '#count_registry' do describe '#count_registry' 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 file registries for attachments' do it 'counts file registries for attachments' 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, missing_on_primary: true)
...@@ -423,9 +267,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -423,9 +267,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
context 'with selective sync by namespace' do context 'with selective sync by namespace' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'namespaces', namespaces: [synced_group]) }
secondary.update!(selective_sync_type: 'namespaces', namespaces: [synced_group])
end
it 'does not apply the selective sync restriction' do 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, :failed, file_id: upload_1.id, missing_on_primary: true)
...@@ -439,9 +281,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -439,9 +281,7 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
context 'with selective sync by shard' do context 'with selective sync by shard' do
before do let(:secondary) { create(:geo_node, selective_sync_type: 'shards', selective_sync_shards: ['broken']) }
secondary.update!(selective_sync_type: 'shards', selective_sync_shards: ['broken'])
end
it 'does not apply the selective sync restriction' do 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, :failed, file_id: upload_1.id)
...@@ -455,6 +295,4 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do ...@@ -455,6 +295,4 @@ describe Geo::AttachmentRegistryFinder, :geo, :geo_fdw do
end end
end end
end end
it_behaves_like 'a file registry finder'
end end
...@@ -20,7 +20,7 @@ describe Geo::JobArtifactRegistryFinder, :geo_fdw do ...@@ -20,7 +20,7 @@ describe Geo::JobArtifactRegistryFinder, :geo_fdw do
stub_artifacts_object_storage stub_artifacts_object_storage
end end
shared_examples 'counts all the things' do context 'counts all the things' do
describe '#count_syncable' do describe '#count_syncable' do
let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) } let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) } let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) }
...@@ -399,7 +399,7 @@ describe Geo::JobArtifactRegistryFinder, :geo_fdw do ...@@ -399,7 +399,7 @@ describe Geo::JobArtifactRegistryFinder, :geo_fdw do
end end
end end
shared_examples 'finds all the things' do context 'finds all the things' do
describe '#find_unsynced' do describe '#find_unsynced' do
let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) } let!(:job_artifact_1) { create(:ci_job_artifact, project: synced_project) }
let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) } let!(:job_artifact_2) { create(:ci_job_artifact, project: unsynced_project) }
......
...@@ -31,7 +31,7 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -31,7 +31,7 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
stub_lfs_object_storage stub_lfs_object_storage
end end
shared_examples 'counts all the things' do context 'counts all the things' do
describe '#count_syncable' do describe '#count_syncable' do
before do before do
allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil) allow_any_instance_of(LfsObjectsProject).to receive(:update_project_statistics).and_return(nil)
...@@ -361,7 +361,7 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do ...@@ -361,7 +361,7 @@ describe Geo::LfsObjectRegistryFinder, :geo_fdw do
end end
end end
shared_examples 'finds all the things' do context 'finds all the things' do
describe '#find_unsynced' do describe '#find_unsynced' do
it 'returns LFS objects without an entry on the tracking database' do it 'returns LFS objects without an entry on the tracking database' do
create(:geo_file_registry, :lfs, file_id: lfs_object_1.id) create(:geo_file_registry, :lfs, file_id: lfs_object_1.id)
......
# frozen_string_literal: true
require 'spec_helper'
describe Gitlab::Geo::FileDownloader, :geo do
include EE::GeoHelpers
set(:primary_node) { create(:geo_node, :primary) }
set(:secondary_node) { create(:geo_node) }
subject { downloader.execute }
let(:upload) { create(:upload, :issuable_upload, :with_file) }
let(:downloader) { described_class.new(:file, upload.id) }
context 'when in primary geo node' do
before do
stub_current_geo_node(primary_node)
end
it 'fails to download the file' do
expect(subject.success).to be_falsey
expect(subject.primary_missing_file).to be_falsey
end
end
context 'when in a secondary geo node' do
before do
stub_current_geo_node(secondary_node)
stub_geo_file_transfer(:file, upload)
end
it 'downloads the file' do
expect(subject.success).to be_truthy
expect(subject.primary_missing_file).to be_falsey
end
end
def stub_geo_file_transfer(file_type, upload)
url = primary_node.geo_transfers_url(file_type, upload.id.to_s)
stub_request(:get, url).to_return(status: 200, body: upload.build_uploader.file.read, headers: {})
end
end
...@@ -17,7 +17,4 @@ shared_examples_for 'a file registry finder' do ...@@ -17,7 +17,4 @@ shared_examples_for 'a file registry finder' do
expect(subject).to respond_to(method) expect(subject).to respond_to(method)
end end
end end
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