Refactor Geo finders specs

Refactor code to make the finder class
closer to a Geo replicator.
parent 8da7e8e6
...@@ -43,13 +43,6 @@ module Geo ...@@ -43,13 +43,6 @@ module Geo
end end
# rubocop:enable CodeReuse/ActiveRecord # rubocop:enable CodeReuse/ActiveRecord
# @!method registry_class
# Return an ActiveRecord::Base class for the tracked type
def registry_class
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
# @!method registry_count # @!method registry_count
# Return a count of the registry records for the tracked type(s) # Return a count of the registry records for the tracked type(s)
def registry_count def registry_count
...@@ -69,5 +62,12 @@ module Geo ...@@ -69,5 +62,12 @@ module Geo
def failed_count def failed_count
registry_class.failed.count registry_class.failed.count
end end
# @!method registry_class
# Return an ActiveRecord::Base class for the tracked type
def registry_class
raise NotImplementedError,
"#{self.class} does not implement #{__method__}"
end
end end
end end
...@@ -15,7 +15,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry ...@@ -15,7 +15,7 @@ class Geo::DesignRegistry < Geo::BaseRegistry
scope :failed, -> { with_state(:failed) } scope :failed, -> { with_state(:failed) }
scope :synced, -> { with_state(:synced) } scope :synced, -> { with_state(:synced) }
scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) } scope :retry_due, -> { where(arel_table[:retry_at].eq(nil).or(arel_table[:retry_at].lt(Time.current))) }
scope :retryable, -> { pending.or(failed.retry_due) } scope :retryable, -> { failed.retry_due }
state_machine :state, initial: :pending do state_machine :state, initial: :pending do
state :started state :started
......
...@@ -3,91 +3,26 @@ ...@@ -3,91 +3,26 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Geo::AttachmentRegistryFinder, :geo do RSpec.describe Geo::AttachmentRegistryFinder, :geo do
it_behaves_like 'a file registry finder' do
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:upload_1) { create(:upload, model: project) }
let_it_be(:upload_2) { create(:upload, model: project) }
let_it_be(:upload_3) { create(:upload, :issuable_upload, model: project) }
let_it_be(:upload_4) { create(:upload, model: project) }
let_it_be(:upload_5) { create(:upload, model: project) }
let_it_be(:upload_6) { create(:upload, :personal_snippet_upload) }
let_it_be(:upload_7) { create(:upload, :object_storage, model: project) }
let_it_be(:upload_8) { create(:upload, :object_storage, model: project) }
let_it_be(:upload_9) { create(:upload, :object_storage, model: project) }
let_it_be(:registry_upload_1) { create(:geo_upload_registry, :attachment, :failed, file_id: upload_1.id) } let_it_be(:replicable_1) { create(:upload, model: project) }
let_it_be(:registry_upload_2) { create(:geo_upload_registry, :attachment, file_id: upload_2.id, missing_on_primary: true) } let_it_be(:replicable_2) { create(:upload, model: project) }
let_it_be(:registry_upload_3) { create(:geo_upload_registry, :attachment, :never_synced, file_id: upload_3.id) } let_it_be(:replicable_3) { create(:upload, :issuable_upload, model: project) }
let_it_be(:registry_upload_4) { create(:geo_upload_registry, :attachment, :failed, file_id: upload_4.id) } let_it_be(:replicable_4) { create(:upload, model: project) }
let_it_be(:registry_upload_5) { create(:geo_upload_registry, :attachment, file_id: upload_5.id, missing_on_primary: true, retry_at: 1.day.ago) } let_it_be(:replicable_5) { create(:upload, model: project) }
let_it_be(:registry_upload_6) { create(:geo_upload_registry, :attachment, :failed, file_id: upload_6.id) } let_it_be(:replicable_6) { create(:upload, :personal_snippet_upload) }
let_it_be(:registry_upload_7) { create(:geo_upload_registry, :attachment, :failed, file_id: upload_7.id, missing_on_primary: true) } let_it_be(:replicable_7) { create(:upload, :object_storage, model: project) }
let_it_be(:registry_upload_8) { create(:geo_upload_registry, :attachment, :never_synced, file_id: upload_8.id) } let_it_be(:replicable_8) { create(:upload, :object_storage, model: project) }
let_it_be(:replicable_9) { create(:upload, :object_storage, model: project) }
describe '#registry_count' do
it 'counts registries for uploads' do let_it_be(:registry_1) { create(:geo_upload_registry, :attachment, :failed, file_id: replicable_1.id) }
expect(subject.registry_count).to eq 8 let_it_be(:registry_2) { create(:geo_upload_registry, :attachment, file_id: replicable_2.id, missing_on_primary: true) }
end let_it_be(:registry_3) { create(:geo_upload_registry, :attachment, :never_synced, file_id: replicable_3.id) }
end let_it_be(:registry_4) { create(:geo_upload_registry, :attachment, :failed, file_id: replicable_4.id) }
let_it_be(:registry_5) { create(:geo_upload_registry, :attachment, file_id: replicable_5.id, missing_on_primary: true, retry_at: 1.day.ago) }
describe '#synced_count' do let_it_be(:registry_6) { create(:geo_upload_registry, :attachment, :failed, file_id: replicable_6.id) }
it 'counts registries that has been synced' do let_it_be(:registry_7) { create(:geo_upload_registry, :attachment, :failed, file_id: replicable_7.id, missing_on_primary: true) }
expect(subject.synced_count).to eq 2 let_it_be(:registry_8) { create(:geo_upload_registry, :attachment, :never_synced, file_id: replicable_8.id) }
end
end
describe '#failed_count' do
it 'counts registries that sync has failed' do
expect(subject.failed_count).to eq 4
end
end
describe '#synced_missing_on_primary_count' do
it 'counts registries that have been synced and are missing on the primary, excluding not synced ones' do
expect(subject.synced_missing_on_primary_count).to eq 2
end
end
describe '#find_unsynced_registries' do
it 'returns registries for uploads that have never been synced' do
registries = subject.find_unsynced_registries(batch_size: 10)
expect(registries).to match_ids(registry_upload_3, registry_upload_8)
end
it 'excludes except_ids' do
registries = subject.find_unsynced_registries(batch_size: 10, except_ids: [upload_3.id])
expect(registries).to match_ids(registry_upload_8)
end end
end
describe '#find_failed_registries' do
it 'returns registries for job artifacts that have failed to sync' do
registries = subject.find_failed_registries(batch_size: 10)
expect(registries).to match_ids(registry_upload_1, registry_upload_4, registry_upload_6, registry_upload_7)
end
it 'excludes except_ids' do
registries = subject.find_failed_registries(batch_size: 10, except_ids: [upload_4.id, upload_7.id])
expect(registries).to match_ids(registry_upload_1, registry_upload_6)
end
end
describe '#find_retryable_synced_missing_on_primary_registries' do
it 'returns registries for job artifacts that have been synced and are missing on the primary' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10)
expect(registries).to match_ids(registry_upload_2, registry_upload_5)
end
it 'excludes except_ids' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10, except_ids: [upload_5.id])
expect(registries).to match_ids(registry_upload_2)
end
end
it_behaves_like 'a file registry finder'
end end
# frozen_string_literal: true # frozen_string_literal: true
require 'spec_helper' require 'spec_helper'
RSpec.describe Geo::ContainerRepositoryRegistryFinder, :geo do RSpec.describe Geo::ContainerRepositoryRegistryFinder, :geo do
let_it_be(:project) { create(:project) } it_behaves_like 'a registry finder' do
let_it_be(:container_repository_1) { create(:container_repository, project: project) }
let_it_be(:container_repository_2) { create(:container_repository, project: project) }
let_it_be(:container_repository_3) { create(:container_repository, project: project) }
let_it_be(:container_repository_4) { create(:container_repository, project: project) }
let_it_be(:container_repository_5) { create(:container_repository, project: project) }
let_it_be(:container_repository_6) { create(:container_repository, project: project) }
before do before do
stub_registry_replication_config(enabled: true) stub_registry_replication_config(enabled: true)
end end
describe '#registry_count' do let_it_be(:project) { create(:project) }
it 'returns number of container registries' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
expect(subject.registry_count).to eq(2)
end
end
describe '#synced_count' do
it 'returns only synced registry' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
expect(subject.synced_count).to eq(1)
end
end
describe '#failed_count' do
it 'returns only failed registry' do
create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id)
create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_3.id)
expect(subject.failed_count).to eq(1)
end
end
describe '#find_unsynced_registries' do
let_it_be(:registry_container_registry_1) { create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id) }
let_it_be(:registry_container_registry_2) { create(:container_repository_registry, :sync_failed, container_repository_id: container_repository_2.id) }
let_it_be(:registry_container_registry_3) { create(:container_repository_registry, container_repository_id: container_repository_3.id, last_synced_at: nil) }
let_it_be(:registry_container_registry_4) { create(:container_repository_registry, container_repository_id: container_repository_4.id, last_synced_at: 3.days.ago, retry_at: 2.days.ago) }
let_it_be(:registry_container_registry_5) { create(:container_repository_registry, container_repository_id: container_repository_5.id, last_synced_at: 6.days.ago) }
let_it_be(:registry_container_registry_6) { create(:container_repository_registry, container_repository_id: container_repository_6.id, last_synced_at: nil) }
it 'returns registries for projects that have never been synced' do
registries = subject.find_unsynced_registries(batch_size: 10)
expect(registries).to match_ids(registry_container_registry_3, registry_container_registry_6)
end
it 'excludes except_ids' do
registries = subject.find_unsynced_registries(batch_size: 10, except_ids: [container_repository_3.id])
expect(registries).to match_ids(registry_container_registry_6)
end
end
describe '#find_failed_registries' do
let_it_be(:registry_container_registry_1) { create(:container_repository_registry, :synced, container_repository_id: container_repository_1.id) }
let_it_be(:registry_container_registry_2) { create(:container_repository_registry, :sync_started, container_repository_id: container_repository_2.id) }
let_it_be(:registry_container_registry_3) { create(:container_repository_registry, state: :failed, container_repository_id: container_repository_3.id, last_synced_at: nil) }
let_it_be(:registry_container_registry_4) { create(:container_repository_registry, state: :failed, container_repository_id: container_repository_4.id, last_synced_at: 3.days.ago, retry_at: 2.days.ago) }
let_it_be(:registry_container_registry_5) { create(:container_repository_registry, state: :failed, container_repository_id: container_repository_5.id, last_synced_at: 6.days.ago) }
let_it_be(:registry_container_registry_6) { create(:container_repository_registry, state: :failed, container_repository_id: container_repository_6.id, last_synced_at: nil) }
it 'returns registries for projects that have been recently updated' do
registries = subject.find_failed_registries(batch_size: 10)
expect(registries).to match_ids(registry_container_registry_3, registry_container_registry_4, registry_container_registry_5, registry_container_registry_6)
end
it 'excludes except_ids' do
registries = subject.find_failed_registries(batch_size: 10, except_ids: [container_repository_4.id, container_repository_5.id, container_repository_6.id])
expect(registries).to match_ids(registry_container_registry_3) let_it_be(:replicable_1) { create(:container_repository, project: project) }
end let_it_be(:replicable_2) { create(:container_repository, project: project) }
let_it_be(:replicable_3) { create(:container_repository, project: project) }
let_it_be(:replicable_4) { create(:container_repository, project: project) }
let_it_be(:replicable_5) { create(:container_repository, project: project) }
let_it_be(:replicable_6) { create(:container_repository, project: project) }
let_it_be(:replicable_7) { create(:container_repository, project: project) }
let_it_be(:replicable_8) { create(:container_repository, project: project) }
let_it_be(:registry_1) { create(:container_repository_registry, :sync_failed, container_repository_id: replicable_1.id) }
let_it_be(:registry_2) { create(:container_repository_registry, :synced, container_repository_id: replicable_2.id) }
let_it_be(:registry_3) { create(:container_repository_registry, container_repository_id: replicable_3.id) }
let_it_be(:registry_4) { create(:container_repository_registry, :sync_failed, container_repository_id: replicable_4.id) }
let_it_be(:registry_5) { create(:container_repository_registry, :synced, container_repository_id: replicable_5.id) }
let_it_be(:registry_6) { create(:container_repository_registry, :sync_failed, container_repository_id: replicable_6.id) }
let_it_be(:registry_7) { create(:container_repository_registry, :sync_failed, container_repository_id: replicable_7.id) }
let_it_be(:registry_8) { create(:container_repository_registry, container_repository_id: replicable_8.id) }
end end
end end
...@@ -2,65 +2,29 @@ ...@@ -2,65 +2,29 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Geo::DesignRegistryFinder, :geo do RSpec.describe Geo::DesignRegistryFinder, :geo do
let_it_be(:group) { create(:group) } it_behaves_like 'a registry finder' do
let_it_be(:project_1) { create(:project, group: group) } before do
let_it_be(:project_2) { create(:project, group: group) } stub_registry_replication_config(enabled: true)
let_it_be(:project_3) { create(:project, group: group) }
let_it_be(:project_4) { create(:project, group: group) }
let_it_be(:project_5) { create(:project, :broken_storage, group: group) }
let_it_be(:project_6) { create(:project, :broken_storage, group: group) }
let_it_be(:project_7) { create(:project, group: group) }
let_it_be(:registry_project_1) { create(:geo_design_registry, :synced, project_id: project_1.id) }
let_it_be(:registry_project_2) { create(:geo_design_registry, :sync_failed, project_id: project_2.id) }
let_it_be(:registry_project_3) { create(:geo_design_registry, project_id: project_3.id, last_synced_at: nil) }
let_it_be(:registry_project_4) { create(:geo_design_registry, project_id: project_4.id, last_synced_at: 3.days.ago, retry_at: 2.days.ago) }
let_it_be(:registry_project_5) { create(:geo_design_registry, project_id: project_5.id, last_synced_at: 6.days.ago) }
let_it_be(:registry_project_6) { create(:geo_design_registry, project_id: project_6.id, last_synced_at: nil) }
describe '#registry_count' do
it 'returns number of desgin registries' do
expect(subject.registry_count).to eq(6)
end
end
describe '#synced_count' do
it 'returns number of synced registries' do
expect(subject.synced_count).to eq(1)
end
end
describe '#failed_count' do
it 'returns number of failed registries' do
expect(subject.failed_count).to eq(1)
end
end
describe '#find_unsynced_registries' do
it 'returns registries for projects that have never been synced' do
registries = subject.find_unsynced_registries(batch_size: 10)
expect(registries).to match_ids(registry_project_3, registry_project_6)
end
it 'excludes except_ids' do
registries = subject.find_unsynced_registries(batch_size: 10, except_ids: [project_3.id])
expect(registries).to match_ids(registry_project_6)
end
end end
describe '#find_failed_registries' do let_it_be(:group) { create(:group) }
it 'returns registries for projects that have been recently updated' do
registries = subject.find_failed_registries(batch_size: 10)
expect(registries).to match_ids(registry_project_2, registry_project_3, registry_project_4, registry_project_5, registry_project_6)
end
it 'excludes except_ids' do
registries = subject.find_failed_registries(batch_size: 10, except_ids: [project_4.id, project_5.id, project_6.id])
expect(registries).to match_ids(registry_project_2, registry_project_3) let_it_be(:replicable_1) { create(:project, group: group) }
end let_it_be(:replicable_2) { create(:project, group: group) }
let_it_be(:replicable_3) { create(:project, group: group) }
let_it_be(:replicable_4) { create(:project, group: group) }
let_it_be(:replicable_5) { create(:project, group: group) }
let_it_be(:replicable_6) { create(:project, group: group) }
let_it_be(:replicable_7) { create(:project, group: group) }
let_it_be(:replicable_8) { create(:project, group: group) }
let_it_be(:registry_1) { create(:geo_design_registry, :sync_failed, project_id: replicable_1.id) }
let_it_be(:registry_2) { create(:geo_design_registry, :synced, project_id: replicable_2.id) }
let_it_be(:registry_3) { create(:geo_design_registry, project_id: replicable_3.id) }
let_it_be(:registry_4) { create(:geo_design_registry, :sync_failed, project_id: replicable_4.id) }
let_it_be(:registry_5) { create(:geo_design_registry, :synced, project_id: replicable_5.id) }
let_it_be(:registry_6) { create(:geo_design_registry, :sync_failed, project_id: replicable_6.id) }
let_it_be(:registry_7) { create(:geo_design_registry, :sync_failed, project_id: replicable_7.id) }
let_it_be(:registry_8) { create(:geo_design_registry, project_id: replicable_8.id) }
end end
end end
# frozen_string_literal: true
require 'spec_helper'
RSpec.describe Geo::FileRegistryFinder, :geo do
context 'with abstract methods' do
%w[
registry_class
].each do |required_method|
it "requires subclasses to implement #{required_method}" do
expect { subject.send(required_method) }.to raise_error(NotImplementedError)
end
end
end
end
...@@ -3,95 +3,29 @@ ...@@ -3,95 +3,29 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Geo::JobArtifactRegistryFinder, :geo do RSpec.describe Geo::JobArtifactRegistryFinder, :geo do
it_behaves_like 'a file registry finder' do
before do before do
stub_artifacts_object_storage stub_artifacts_object_storage
end end
let_it_be(:project) { create(:project) } let_it_be(:project) { create(:project) }
let_it_be(:ci_job_artifact_1) { create(:ci_job_artifact, project: project) } let_it_be(:replicable_1) { create(:ci_job_artifact, project: project) }
let_it_be(:ci_job_artifact_2) { create(:ci_job_artifact, project: project) } let_it_be(:replicable_2) { create(:ci_job_artifact, project: project) }
let_it_be(:ci_job_artifact_3) { create(:ci_job_artifact, project: project) } let_it_be(:replicable_3) { create(:ci_job_artifact, project: project) }
let_it_be(:ci_job_artifact_4) { create(:ci_job_artifact, project: project) } let_it_be(:replicable_4) { create(:ci_job_artifact, project: project) }
let_it_be(:ci_job_artifact_5) { create(:ci_job_artifact, project: project) } let_it_be(:replicable_5) { create(:ci_job_artifact, project: project) }
let!(:ci_job_artifact_remote_1) { create(:ci_job_artifact, :remote_store, project: project) } let!(:replicable_6) { create(:ci_job_artifact, :remote_store, project: project) }
let!(:ci_job_artifact_remote_2) { create(:ci_job_artifact, :remote_store, project: project) } let!(:replicable_7) { create(:ci_job_artifact, :remote_store, project: project) }
let!(:ci_job_artifact_remote_3) { create(:ci_job_artifact, :remote_store, project: project) } let!(:replicable_8) { create(:ci_job_artifact, :remote_store, project: project) }
let_it_be(:registry_ci_job_artifact_1) { create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_1.id) } let_it_be(:registry_1) { create(:geo_job_artifact_registry, :failed, artifact_id: replicable_1.id) }
let_it_be(:registry_ci_job_artifact_2) { create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_2.id, missing_on_primary: true) } let_it_be(:registry_2) { create(:geo_job_artifact_registry, artifact_id: replicable_2.id, missing_on_primary: true) }
let_it_be(:registry_ci_job_artifact_3) { create(:geo_job_artifact_registry, :never_synced, artifact_id: ci_job_artifact_3.id) } let_it_be(:registry_3) { create(:geo_job_artifact_registry, :never_synced, artifact_id: replicable_3.id) }
let_it_be(:registry_ci_job_artifact_4) { create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_4.id) } let_it_be(:registry_4) { create(:geo_job_artifact_registry, :failed, artifact_id: replicable_4.id) }
let_it_be(:registry_ci_job_artifact_5) { create(:geo_job_artifact_registry, artifact_id: ci_job_artifact_5.id, missing_on_primary: true, retry_at: 1.day.ago) } let_it_be(:registry_5) { create(:geo_job_artifact_registry, artifact_id: replicable_5.id, missing_on_primary: true, retry_at: 1.day.ago) }
let!(:registry_ci_job_artifact_remote_1) { create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_remote_1.id) } let!(:registry_6) { create(:geo_job_artifact_registry, :failed, artifact_id: replicable_6.id) }
let!(:registry_ci_job_artifact_remote_2) { create(:geo_job_artifact_registry, :failed, artifact_id: ci_job_artifact_remote_2.id, missing_on_primary: true) } let!(:registry_7) { create(:geo_job_artifact_registry, :failed, artifact_id: replicable_7.id, missing_on_primary: true) }
let!(:registry_ci_job_artifact_remote_3) { create(:geo_job_artifact_registry, :never_synced, artifact_id: ci_job_artifact_remote_3.id) } let!(:registry_8) { create(:geo_job_artifact_registry, :never_synced, artifact_id: replicable_8.id) }
describe '#registry_count' do
it 'counts registries for job artifacts' do
expect(subject.registry_count).to eq 8
end
end
describe '#synced_count' do
it 'counts registries that has been synced' do
expect(subject.synced_count).to eq 2
end
end
describe '#failed_count' do
it 'counts registries that sync has failed' do
expect(subject.failed_count).to eq 4
end
end
describe '#synced_missing_on_primary_count' do
it 'counts registries that have been synced and are missing on the primary, excluding not synced ones' do
expect(subject.synced_missing_on_primary_count).to eq 2
end
end
describe '#find_unsynced_registries' do
it 'returns registries for job artifacts that have never been synced' do
registries = subject.find_unsynced_registries(batch_size: 10)
expect(registries).to match_ids(registry_ci_job_artifact_3, registry_ci_job_artifact_remote_3)
end
it 'excludes except_ids' do
registries = subject.find_unsynced_registries(batch_size: 10, except_ids: [ci_job_artifact_3.id])
expect(registries).to match_ids(registry_ci_job_artifact_remote_3)
end
end
describe '#find_failed_registries' do
it 'returns registries for job artifacts that have failed to sync' do
registries = subject.find_failed_registries(batch_size: 10)
expect(registries).to match_ids(registry_ci_job_artifact_1, registry_ci_job_artifact_4, registry_ci_job_artifact_remote_1, registry_ci_job_artifact_remote_2)
end
it 'excludes except_ids' do
registries = subject.find_failed_registries(batch_size: 10, except_ids: [ci_job_artifact_4.id, ci_job_artifact_remote_2.id])
expect(registries).to match_ids(registry_ci_job_artifact_1, registry_ci_job_artifact_remote_1)
end
end end
describe '#find_retryable_synced_missing_on_primary_registries' do
it 'returns registries for job artifacts that have been synced and are missing on the primary' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10)
expect(registries).to match_ids(registry_ci_job_artifact_2, registry_ci_job_artifact_5)
end
it 'excludes except_ids' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10, except_ids: [ci_job_artifact_5.id])
expect(registries).to match_ids(registry_ci_job_artifact_2)
end
end
it_behaves_like 'a file registry finder'
end end
...@@ -3,93 +3,27 @@ ...@@ -3,93 +3,27 @@
require 'spec_helper' require 'spec_helper'
RSpec.describe Geo::LfsObjectRegistryFinder, :geo do RSpec.describe Geo::LfsObjectRegistryFinder, :geo do
it_behaves_like 'a file registry finder' do
before do before do
stub_lfs_object_storage stub_lfs_object_storage
end end
let_it_be(:lfs_object_1) { create(:lfs_object) } let_it_be(:replicable_1) { create(:lfs_object) }
let_it_be(:lfs_object_2) { create(:lfs_object) } let_it_be(:replicable_2) { create(:lfs_object) }
let_it_be(:lfs_object_3) { create(:lfs_object) } let_it_be(:replicable_3) { create(:lfs_object) }
let_it_be(:lfs_object_4) { create(:lfs_object) } let_it_be(:replicable_4) { create(:lfs_object) }
let_it_be(:lfs_object_5) { create(:lfs_object) } let_it_be(:replicable_5) { create(:lfs_object) }
let!(:lfs_object_remote_1) { create(:lfs_object, :object_storage) } let!(:replicable_6) { create(:lfs_object, :object_storage) }
let!(:lfs_object_remote_2) { create(:lfs_object, :object_storage) } let!(:replicable_7) { create(:lfs_object, :object_storage) }
let!(:lfs_object_remote_3) { create(:lfs_object, :object_storage) } let!(:replicable_8) { create(:lfs_object, :object_storage) }
let_it_be(:registry_lfs_object_1) { create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_1.id) } let_it_be(:registry_1) { create(:geo_lfs_object_registry, :failed, lfs_object_id: replicable_1.id) }
let_it_be(:registry_lfs_object_2) { create(:geo_lfs_object_registry, lfs_object_id: lfs_object_2.id, missing_on_primary: true) } let_it_be(:registry_2) { create(:geo_lfs_object_registry, lfs_object_id: replicable_2.id, missing_on_primary: true) }
let_it_be(:registry_lfs_object_3) { create(:geo_lfs_object_registry, :never_synced, lfs_object_id: lfs_object_3.id) } let_it_be(:registry_3) { create(:geo_lfs_object_registry, :never_synced, lfs_object_id: replicable_3.id) }
let_it_be(:registry_lfs_object_4) { create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_4.id) } let_it_be(:registry_4) { create(:geo_lfs_object_registry, :failed, lfs_object_id: replicable_4.id) }
let_it_be(:registry_lfs_object_5) { create(:geo_lfs_object_registry, lfs_object_id: lfs_object_5.id, missing_on_primary: true, retry_at: 1.day.ago) } let_it_be(:registry_5) { create(:geo_lfs_object_registry, lfs_object_id: replicable_5.id, missing_on_primary: true, retry_at: 1.day.ago) }
let!(:registry_lfs_object_remote_1) { create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_remote_1.id) } let!(:registry_6) { create(:geo_lfs_object_registry, :failed, lfs_object_id: replicable_6.id) }
let!(:registry_lfs_object_remote_2) { create(:geo_lfs_object_registry, :failed, lfs_object_id: lfs_object_remote_2.id, missing_on_primary: true) } let!(:registry_7) { create(:geo_lfs_object_registry, :failed, lfs_object_id: replicable_7.id, missing_on_primary: true) }
let!(:registry_lfs_object_remote_3) { create(:geo_lfs_object_registry, :never_synced, lfs_object_id: lfs_object_remote_3.id) } let!(:registry_8) { create(:geo_lfs_object_registry, :never_synced, lfs_object_id: replicable_8.id) }
describe '#registry_count' do
it 'counts registries for LFS objects' do
expect(subject.registry_count).to eq 8
end
end
describe '#synced_count' do
it 'counts registries that has been synced' do
expect(subject.synced_count).to eq 2
end
end
describe '#failed_count' do
it 'counts registries that sync has failed' do
expect(subject.failed_count).to eq 4
end
end
describe '#synced_missing_on_primary_count' do
it 'counts registries that have been synced and are missing on the primary, excluding not synced ones' do
expect(subject.synced_missing_on_primary_count).to eq 2
end
end
describe '#find_unsynced_registries' do
it 'returns registries for LFS objects that have never been synced' do
registries = subject.find_unsynced_registries(batch_size: 10)
expect(registries).to match_ids(registry_lfs_object_3, registry_lfs_object_remote_3)
end
it 'excludes except_ids' do
registries = subject.find_unsynced_registries(batch_size: 10, except_ids: [lfs_object_3.id])
expect(registries).to match_ids(registry_lfs_object_remote_3)
end
end
describe '#find_failed_registries' do
it 'returns registries for LFS objects that have failed to sync' do
registries = subject.find_failed_registries(batch_size: 10)
expect(registries).to match_ids(registry_lfs_object_1, registry_lfs_object_4, registry_lfs_object_remote_1, registry_lfs_object_remote_2)
end
it 'excludes except_ids' do
registries = subject.find_failed_registries(batch_size: 10, except_ids: [lfs_object_4.id, lfs_object_remote_2.id])
expect(registries).to match_ids(registry_lfs_object_1, registry_lfs_object_remote_1)
end
end end
describe '#find_retryable_synced_missing_on_primary_registries' do
it 'returns registries for LFS objects that have been synced and are missing on the primary' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10)
expect(registries).to match_ids(registry_lfs_object_2, registry_lfs_object_5)
end
it 'excludes except_ids' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10, except_ids: [lfs_object_5.id])
expect(registries).to match_ids(registry_lfs_object_2)
end
end
it_behaves_like 'a file registry finder'
end end
# frozen_string_literal: true # frozen_string_literal: true
RSpec.shared_examples 'a file registry finder' do RSpec.shared_examples 'a file registry finder' do
include_examples 'a registry finder'
it 'responds to file registry finder methods' do it 'responds to file registry finder methods' do
file_registry_finder_methods = %i{ file_registry_finder_methods = %i{
registry_class
registry_count
synced_count
failed_count
synced_missing_on_primary_count synced_missing_on_primary_count
find_failed_registries
find_retryable_synced_missing_on_primary_registries find_retryable_synced_missing_on_primary_registries
} }
...@@ -16,4 +13,24 @@ RSpec.shared_examples 'a file registry finder' do ...@@ -16,4 +13,24 @@ RSpec.shared_examples 'a file registry finder' do
expect(subject).to respond_to(method) expect(subject).to respond_to(method)
end end
end end
describe '#synced_missing_on_primary_count' do
it 'counts registries that have been synced and are missing on the primary, excluding not synced ones' do
expect(subject.synced_missing_on_primary_count).to eq 2
end
end
describe '#find_retryable_synced_missing_on_primary_registries' do
it 'returns registries that have been synced and are missing on the primary' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10)
expect(registries).to match_ids(registry_2, registry_5)
end
it 'excludes except_ids' do
registries = subject.find_retryable_synced_missing_on_primary_registries(batch_size: 10, except_ids: [replicable_5.id])
expect(registries).to match_ids(registry_2)
end
end
end end
# frozen_string_literal: true
RSpec.shared_examples 'a registry finder' do
it 'responds to registry finder methods' do
registry_finder_methods = %i{
failed_count
find_failed_registries
find_unsynced_registries
registry_class
registry_count
synced_count
}
registry_finder_methods.each do |method|
expect(subject).to respond_to(method)
end
end
describe '#registry_count' do
it 'counts registries' do
expect(subject.registry_count).to eq 8
end
end
describe '#synced_count' do
it 'counts registries that has been synced' do
expect(subject.synced_count).to eq 2
end
end
describe '#failed_count' do
it 'counts registries that sync has failed' do
expect(subject.failed_count).to eq 4
end
end
describe '#find_unsynced_registries' do
it 'returns registries that have never been synced' do
registries = subject.find_unsynced_registries(batch_size: 10)
expect(registries).to match_ids(registry_3, registry_8)
end
it 'excludes except_ids' do
registries = subject.find_unsynced_registries(batch_size: 10, except_ids: [replicable_3.id])
expect(registries).to match_ids(registry_8)
end
end
describe '#find_failed_registries' do
it 'returns registries for that have failed to sync' do
registries = subject.find_failed_registries(batch_size: 10)
expect(registries).to match_ids(registry_1, registry_4, registry_6, registry_7)
end
it 'excludes except_ids' do
registries = subject.find_failed_registries(batch_size: 10, except_ids: [replicable_4.id, replicable_7.id])
expect(registries).to match_ids(registry_1, registry_6)
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