From 7bd34f8b23f26fc4ebd10bcc3f2e0bae7cdd6520 Mon Sep 17 00:00:00 2001 From: Claire Date: Thu, 4 May 2023 10:13:00 +0200 Subject: [PATCH] Fix infinite loop in AccountsStatusesCleanupScheduler (#24840) --- .../accounts_statuses_cleanup_scheduler.rb | 1 + .../accounts_statuses_cleanup_scheduler_spec.rb | 14 ++++++++++++++ 2 files changed, 15 insertions(+) diff --git a/app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb b/app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb index 5b8c15d2d..a2ab31cc5 100644 --- a/app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb +++ b/app/workers/scheduler/accounts_statuses_cleanup_scheduler.rb @@ -79,6 +79,7 @@ class Scheduler::AccountsStatusesCleanupScheduler # and start back after the last processed account otherwise break if budget.zero? || (num_processed_accounts.zero? && !full_iteration) + full_iteration = false unless first_iteration first_iteration = false end end diff --git a/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb b/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb index 2a7a7ffbb..0b0c4dd48 100644 --- a/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb +++ b/spec/workers/scheduler/accounts_statuses_cleanup_scheduler_spec.rb @@ -141,6 +141,20 @@ describe Scheduler::AccountsStatusesCleanupScheduler do expect { subject.perform }.to change { Status.count }.by(-30) end end + + context 'when there is no work to be done' do + let(:process_set_stub) { [{ 'concurrency' => 400, 'queues' => %w(push default) }] } + + before do + stub_const 'Scheduler::AccountsStatusesCleanupScheduler::MAX_BUDGET', 400 + subject.perform + end + + it 'does not get stuck' do + expect(subject.compute_budget).to eq(400) + expect { subject.perform }.to_not change { Status.count } + end + end end end end