diff options
author | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
---|---|---|
committer | GitLab Bot <gitlab-bot@gitlab.com> | 2021-06-16 21:25:58 +0300 |
commit | a5f4bba440d7f9ea47046a0a561d49adf0a1e6d4 (patch) | |
tree | fb69158581673816a8cd895f9d352dcb3c678b1e /spec/workers/container_expiration_policy_worker_spec.rb | |
parent | d16b2e8639e99961de6ddc93909f3bb5c1445ba1 (diff) |
Add latest changes from gitlab-org/gitlab@14-0-stable-eev14.0.0-rc42
Diffstat (limited to 'spec/workers/container_expiration_policy_worker_spec.rb')
-rw-r--r-- | spec/workers/container_expiration_policy_worker_spec.rb | 104 |
1 files changed, 17 insertions, 87 deletions
diff --git a/spec/workers/container_expiration_policy_worker_spec.rb b/spec/workers/container_expiration_policy_worker_spec.rb index e8f9a972f10..8562935b0b5 100644 --- a/spec/workers/container_expiration_policy_worker_spec.rb +++ b/spec/workers/container_expiration_policy_worker_spec.rb @@ -34,101 +34,18 @@ RSpec.describe ContainerExpirationPolicyWorker do end end - context 'With no container expiration policies' do - context 'with loopless disabled' do - before do - stub_feature_flags(container_registry_expiration_policies_loopless: false) - end - - it 'does not execute any policies' do - expect(ContainerRepository).not_to receive(:for_project_id) - - expect { subject }.not_to change { ContainerRepository.cleanup_scheduled.count } - end - end - end - context 'with throttling enabled' do before do stub_feature_flags(container_registry_expiration_policies_throttling: true) end - context 'with loopless disabled' do - before do - stub_feature_flags(container_registry_expiration_policies_loopless: false) - end - - context 'with container expiration policies' do - let_it_be(:container_expiration_policy) { create(:container_expiration_policy, :runnable) } - let_it_be(:container_repository) { create(:container_repository, project: container_expiration_policy.project) } - - before do - expect(worker).to receive(:with_runnable_policy).and_call_original - end - - context 'with a valid container expiration policy' do - it 'schedules the next run' do - expect { subject }.to change { container_expiration_policy.reload.next_run_at } - end - - it 'marks the container repository as scheduled for cleanup' do - expect { subject }.to change { container_repository.reload.cleanup_scheduled? }.from(false).to(true) - expect(ContainerRepository.cleanup_scheduled.count).to eq(1) - end - - it 'calls the limited capacity worker' do - expect(ContainerExpirationPolicies::CleanupContainerRepositoryWorker).to receive(:perform_with_capacity) - - subject - end - end - - context 'with a disabled container expiration policy' do - before do - container_expiration_policy.disable! - end + it 'calls the limited capacity worker' do + expect(ContainerExpirationPolicies::CleanupContainerRepositoryWorker).to receive(:perform_with_capacity) - it 'does not run the policy' do - expect(ContainerRepository).not_to receive(:for_project_id) - - expect { subject }.not_to change { ContainerRepository.cleanup_scheduled.count } - end - end - - context 'with an invalid container expiration policy' do - let(:user) { container_expiration_policy.project.owner } - - before do - container_expiration_policy.update_column(:name_regex, '*production') - end - - it 'disables the policy and tracks an error' do - expect(ContainerRepository).not_to receive(:for_project_id) - expect(Gitlab::ErrorTracking).to receive(:log_exception).with(instance_of(described_class::InvalidPolicyError), container_expiration_policy_id: container_expiration_policy.id) - - expect { subject }.to change { container_expiration_policy.reload.enabled }.from(true).to(false) - expect(ContainerRepository.cleanup_scheduled).to be_empty - end - end - end - - it_behaves_like 'handling a taken exclusive lease' + subject end - context 'with loopless enabled' do - before do - stub_feature_flags(container_registry_expiration_policies_loopless: true) - expect(worker).not_to receive(:with_runnable_policy) - end - - it 'calls the limited capacity worker' do - expect(ContainerExpirationPolicies::CleanupContainerRepositoryWorker).to receive(:perform_with_capacity) - - subject - end - - it_behaves_like 'handling a taken exclusive lease' - end + it_behaves_like 'handling a taken exclusive lease' end context 'with throttling disabled' do @@ -193,5 +110,18 @@ RSpec.describe ContainerExpirationPolicyWorker do end end end + + context 'process stale ongoing cleanups' do + let_it_be(:stuck_cleanup) { create(:container_repository, :cleanup_ongoing, expiration_policy_started_at: 1.day.ago) } + let_it_be(:container_repository) { create(:container_repository, :cleanup_scheduled) } + let_it_be(:container_repository) { create(:container_repository, :cleanup_unfinished) } + + it 'set them as unfinished' do + expect { subject } + .to change { ContainerRepository.cleanup_ongoing.count }.from(1).to(0) + .and change { ContainerRepository.cleanup_unfinished.count }.from(1).to(2) + expect(stuck_cleanup.reload).to be_cleanup_unfinished + end + end end end |