From c541e4dec3a868110d81cf6819e22ddfb3d3ab9a Mon Sep 17 00:00:00 2001
From: Arturo Herrero <arturo.herrero@gmail.com>
Date: Thu, 17 Oct 2024 09:42:41 +0200
Subject: [PATCH] Fix bulk cron worker Rubocop offenses

EE: true
---
 .rubocop_todo/rspec/context_wording.yml        |  1 -
 .rubocop_todo/rspec/expect_in_hook.yml         |  1 -
 .../elastic_index_bulk_cron_worker_spec.rb     | 18 +++++++++---------
 spec/support/rspec_order_todo.yml              |  1 -
 4 files changed, 9 insertions(+), 12 deletions(-)

diff --git a/.rubocop_todo/rspec/context_wording.yml b/.rubocop_todo/rspec/context_wording.yml
index 87b44886027ecc..e7cdd001db2887 100644
--- a/.rubocop_todo/rspec/context_wording.yml
+++ b/.rubocop_todo/rspec/context_wording.yml
@@ -821,7 +821,6 @@ RSpec/ContextWording:
     - 'ee/spec/workers/ci/runners/stale_group_runners_prune_cron_worker_spec.rb'
     - 'ee/spec/workers/ci/upstream_projects_subscriptions_cleanup_worker_spec.rb'
     - 'ee/spec/workers/ee/repository_check/batch_worker_spec.rb'
-    - 'ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb'
     - 'ee/spec/workers/elastic_indexing_control_worker_spec.rb'
     - 'ee/spec/workers/geo/prune_event_log_worker_spec.rb'
     - 'ee/spec/workers/geo/verification_timeout_worker_spec.rb'
diff --git a/.rubocop_todo/rspec/expect_in_hook.yml b/.rubocop_todo/rspec/expect_in_hook.yml
index 7411a614bcf3c8..fd81b7ef95e7ef 100644
--- a/.rubocop_todo/rspec/expect_in_hook.yml
+++ b/.rubocop_todo/rspec/expect_in_hook.yml
@@ -71,7 +71,6 @@ RSpec/ExpectInHook:
     - 'ee/spec/tasks/gitlab/license_rake_spec.rb'
     - 'ee/spec/tasks/gitlab/spdx_rake_spec.rb'
     - 'ee/spec/workers/analytics/cycle_analytics/consistency_worker_spec.rb'
-    - 'ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb'
     - 'ee/spec/workers/elastic_indexing_control_worker_spec.rb'
     - 'ee/spec/workers/geo/secondary/registry_consistency_worker_spec.rb'
     - 'ee/spec/workers/geo/verification_state_backfill_worker_spec.rb'
diff --git a/ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb b/ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb
index e197e375658bad..b9aab2ce503217 100644
--- a/ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb
+++ b/ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb
@@ -18,9 +18,9 @@
   end
 
   describe '.perform' do
-    context 'indexing is not paused' do
+    context 'when indexing is not paused' do
       before do
-        expect(Elastic::IndexingControl).to receive(:non_cached_pause_indexing?).and_return(false)
+        allow(Elastic::IndexingControl).to receive(:non_cached_pause_indexing?).and_return(false)
       end
 
       it 'queues all shards for execution' do
@@ -31,7 +31,7 @@
         worker.perform
       end
 
-      context 'legacy lease is detected' do
+      context 'when legacy lease is detected' do
         before do
           allow(Gitlab::ExclusiveLease).to receive(:get_uuid).with(lease_key).and_return('lease_uuid')
         end
@@ -73,9 +73,9 @@
       end
     end
 
-    context 'indexing is paused' do
+    context 'when indexing is paused' do
       before do
-        expect(Elastic::IndexingControl).to receive(:non_cached_pause_indexing?).and_return(true)
+        allow(Elastic::IndexingControl).to receive(:non_cached_pause_indexing?).and_return(true)
       end
 
       it 'does nothing if indexing is paused' do
@@ -100,8 +100,8 @@
 
     context 'when service returns non-zero counter' do
       before do
-        expect_next_instance_of(::Elastic::ProcessBookkeepingService) do |service|
-          expect(service).to receive(:execute).and_return([15, 0])
+        allow_next_instance_of(::Elastic::ProcessBookkeepingService) do |service|
+          allow(service).to receive(:execute).and_return([15, 0])
         end
       end
 
@@ -155,8 +155,8 @@
 
     context 'when indexing failures occur in the queue' do
       before do
-        expect_next_instance_of(::Elastic::ProcessBookkeepingService) do |service|
-          expect(service).to receive(:execute).and_return([15, 5])
+        allow_next_instance_of(::Elastic::ProcessBookkeepingService) do |service|
+          allow(service).to receive(:execute).and_return([15, 5])
         end
       end
 
diff --git a/spec/support/rspec_order_todo.yml b/spec/support/rspec_order_todo.yml
index 7aa52f7914eb85..6c7e70329cda14 100644
--- a/spec/support/rspec_order_todo.yml
+++ b/spec/support/rspec_order_todo.yml
@@ -2580,7 +2580,6 @@
 - './ee/spec/workers/elastic_cluster_reindexing_cron_worker_spec.rb'
 - './ee/spec/workers/elastic_delete_project_worker_spec.rb'
 - './ee/spec/workers/elastic_full_index_worker_spec.rb'
-- './ee/spec/workers/elastic_index_bulk_cron_worker_spec.rb'
 - './ee/spec/workers/elastic_indexing_control_worker_spec.rb'
 - './ee/spec/workers/elastic_index_initial_bulk_cron_worker_spec.rb'
 - './ee/spec/workers/elastic/migration_worker_spec.rb'
-- 
GitLab