diff options
Diffstat (limited to 'spec/workers/container_registry/cleanup_worker_spec.rb')
-rw-r--r-- | spec/workers/container_registry/cleanup_worker_spec.rb | 71 |
1 files changed, 71 insertions, 0 deletions
diff --git a/spec/workers/container_registry/cleanup_worker_spec.rb b/spec/workers/container_registry/cleanup_worker_spec.rb index 72e1243ccb5..955d2175085 100644 --- a/spec/workers/container_registry/cleanup_worker_spec.rb +++ b/spec/workers/container_registry/cleanup_worker_spec.rb @@ -46,6 +46,77 @@ RSpec.describe ContainerRegistry::CleanupWorker, :aggregate_failures, feature_ca end end + context 'with stale ongoing repair details' do + let_it_be(:stale_updated_at) { (described_class::STALE_REPAIR_DETAIL_THRESHOLD + 5.minutes).ago } + let_it_be(:recent_updated_at) { (described_class::STALE_REPAIR_DETAIL_THRESHOLD - 5.minutes).ago } + let_it_be(:old_repair_detail) { create(:container_registry_data_repair_detail, updated_at: stale_updated_at) } + let_it_be(:new_repair_detail) { create(:container_registry_data_repair_detail, updated_at: recent_updated_at) } + + it 'deletes them' do + expect { perform }.to change { ContainerRegistry::DataRepairDetail.count }.from(2).to(1) + expect(ContainerRegistry::DataRepairDetail.all).to contain_exactly(new_repair_detail) + end + end + + shared_examples 'does not enqueue record repair detail jobs' do + it 'does not enqueue record repair detail jobs' do + expect(ContainerRegistry::RecordDataRepairDetailWorker).not_to receive(:perform_with_capacity) + + perform + end + end + + context 'when on gitlab.com', :saas do + context 'when the gitlab api is supported' do + let(:relation) { instance_double(ActiveRecord::Relation) } + + before do + allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(true) + allow(Project).to receive(:pending_data_repair_analysis).and_return(relation) + end + + context 'when there are pending projects to analyze' do + before do + allow(relation).to receive(:exists?).and_return(true) + end + + it "enqueues record repair detail jobs" do + expect(ContainerRegistry::RecordDataRepairDetailWorker).to receive(:perform_with_capacity) + + perform + end + end + + context 'when there are no pending projects to analyze' do + before do + allow(relation).to receive(:exists?).and_return(false) + end + + it_behaves_like 'does not enqueue record repair detail jobs' + end + end + + context 'when the Gitlab API is not supported' do + before do + allow(ContainerRegistry::GitlabApiClient).to receive(:supports_gitlab_api?).and_return(false) + end + + it_behaves_like 'does not enqueue record repair detail jobs' + end + end + + context 'when not on Gitlab.com' do + it_behaves_like 'does not enqueue record repair detail jobs' + end + + context 'when registry_data_repair_worker feature is disabled' do + before do + stub_feature_flags(registry_data_repair_worker: false) + end + + it_behaves_like 'does not enqueue record repair detail jobs' + end + context 'for counts logging' do let_it_be(:delete_started_at) { (described_class::STALE_DELETE_THRESHOLD + 5.minutes).ago } let_it_be(:stale_delete_container_repository) do |