diff options
Diffstat (limited to 'spec/workers/packages/cleanup_package_registry_worker_spec.rb')
-rw-r--r-- | spec/workers/packages/cleanup_package_registry_worker_spec.rb | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/spec/workers/packages/cleanup_package_registry_worker_spec.rb b/spec/workers/packages/cleanup_package_registry_worker_spec.rb index e43864975f6..e12f2198f66 100644 --- a/spec/workers/packages/cleanup_package_registry_worker_spec.rb +++ b/spec/workers/packages/cleanup_package_registry_worker_spec.rb @@ -5,6 +5,8 @@ require 'spec_helper' RSpec.describe Packages::CleanupPackageRegistryWorker do describe '#perform' do let_it_be_with_reload(:package_files) { create_list(:package_file, 2, :pending_destruction) } + let_it_be(:policy) { create(:packages_cleanup_policy, :runnable) } + let_it_be(:package) { create(:package, project: policy.project) } let(:worker) { described_class.new } @@ -34,6 +36,28 @@ RSpec.describe Packages::CleanupPackageRegistryWorker do end end + context 'with runnable policies' do + it_behaves_like 'an idempotent worker' + + it 'queues the cleanup job' do + expect(Packages::Cleanup::ExecutePolicyWorker).to receive(:perform_with_capacity) + + perform + end + end + + context 'with no runnable policies' do + before do + policy.update_column(:next_run_at, 5.minutes.from_now) + end + + it 'does not queue the cleanup job' do + expect(Packages::Cleanup::ExecutePolicyWorker).not_to receive(:perform_with_capacity) + + perform + end + end + describe 'counts logging' do let_it_be(:processing_package_file) { create(:package_file, status: :processing) } @@ -41,6 +65,7 @@ RSpec.describe Packages::CleanupPackageRegistryWorker do expect(worker).to receive(:log_extra_metadata_on_done).with(:pending_destruction_package_files_count, 2) expect(worker).to receive(:log_extra_metadata_on_done).with(:processing_package_files_count, 1) expect(worker).to receive(:log_extra_metadata_on_done).with(:error_package_files_count, 0) + expect(worker).to receive(:log_extra_metadata_on_done).with(:pending_cleanup_policies_count, 1) perform end |