diff options
Diffstat (limited to 'spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb')
-rw-r--r-- | spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb | 48 |
1 files changed, 40 insertions, 8 deletions
diff --git a/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb b/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb index 0e7b4ea504c..ec10c66968d 100644 --- a/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb +++ b/spec/workers/projects/inactive_projects_deletion_cron_worker_spec.rb @@ -5,6 +5,34 @@ require 'spec_helper' RSpec.describe Projects::InactiveProjectsDeletionCronWorker do include ProjectHelpers + shared_examples 'worker is running for more than 4 minutes' do + before do + subject.instance_variable_set(:@start_time, ::Gitlab::Metrics::System.monotonic_time - 5.minutes) + end + + it 'stores the last processed inactive project_id in redis cache' do + Gitlab::Redis::Cache.with do |redis| + expect { worker.perform } + .to change { redis.get('last_processed_inactive_project_id') }.to(inactive_large_project.id.to_s) + end + end + end + + shared_examples 'worker finishes processing in less than 4 minutes' do + before do + Gitlab::Redis::Cache.with do |redis| + redis.set('last_processed_inactive_project_id', inactive_large_project.id) + end + end + + it 'clears the last processed inactive project_id from redis cache' do + Gitlab::Redis::Cache.with do |redis| + expect { worker.perform } + .to change { redis.get('last_processed_inactive_project_id') }.to(nil) + end + end + end + describe "#perform" do subject(:worker) { described_class.new } @@ -44,7 +72,7 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do end it 'does not invoke Projects::InactiveProjectsDeletionNotificationWorker' do - expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_in) + expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) expect(::Projects::DestroyService).not_to receive(:new) worker.perform @@ -68,7 +96,7 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do end it 'does not invoke Projects::InactiveProjectsDeletionNotificationWorker' do - expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_in) + expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) expect(::Projects::DestroyService).not_to receive(:new) worker.perform @@ -79,11 +107,12 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do expect(inactive_large_project.reload.pending_delete).to eq(false) end + + it_behaves_like 'worker is running for more than 4 minutes' + it_behaves_like 'worker finishes processing in less than 4 minutes' end context 'when feature flag is enabled', :clean_gitlab_redis_shared_state, :sidekiq_inline do - let_it_be(:delay) { anything } - before do stub_feature_flags(inactive_projects_deletion: true) end @@ -93,8 +122,8 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do expect(redis).to receive(:hset).with('inactive_projects_deletion_warning_email_notified', "project:#{inactive_large_project.id}", Date.current) end - expect(::Projects::InactiveProjectsDeletionNotificationWorker).to receive(:perform_in).with( - delay, inactive_large_project.id, deletion_date).and_call_original + expect(::Projects::InactiveProjectsDeletionNotificationWorker).to receive(:perform_async).with( + inactive_large_project.id, deletion_date).and_call_original expect(::Projects::DestroyService).not_to receive(:new) worker.perform @@ -106,7 +135,7 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do Date.current.to_s) end - expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_in) + expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) expect(::Projects::DestroyService).not_to receive(:new) worker.perform @@ -118,7 +147,7 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do 15.months.ago.to_date.to_s) end - expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_in) + expect(::Projects::InactiveProjectsDeletionNotificationWorker).not_to receive(:perform_async) expect(::Projects::DestroyService).to receive(:new).with(inactive_large_project, admin_user, {}) .at_least(:once).and_call_original @@ -131,6 +160,9 @@ RSpec.describe Projects::InactiveProjectsDeletionCronWorker do "project:#{inactive_large_project.id}")).to be_nil end end + + it_behaves_like 'worker is running for more than 4 minutes' + it_behaves_like 'worker finishes processing in less than 4 minutes' end it_behaves_like 'an idempotent worker' |