From acfd7f91bf183f8ac942fa75a80fc44b77cd0d03 Mon Sep 17 00:00:00 2001
From: Omar Qunsul <oqunsul@gitlab.com>
Date: Mon, 15 Apr 2024 16:10:07 +0200
Subject: [PATCH] Fixing Flaky Test in ConsistencyCheckService

Addressing: https://gitlab.com/gitlab-org/gitlab/-/issues/450478
Changelog: fixed
---
 app/services/database/consistency_check_service.rb       | 2 +-
 spec/services/database/consistency_check_service_spec.rb | 6 +++---
 2 files changed, 4 insertions(+), 4 deletions(-)

diff --git a/app/services/database/consistency_check_service.rb b/app/services/database/consistency_check_service.rb
index fee2e79a6cb8c..63648810615b7 100644
--- a/app/services/database/consistency_check_service.rb
+++ b/app/services/database/consistency_check_service.rb
@@ -21,7 +21,7 @@ def initialize(source_model:, target_model:, source_columns:, target_columns:)
     # It compares up to 25 batches (1000 records / batch), or up to 30 seconds
     # for all the batches in total.
     #
-    # It saves the cursor of the next start_id (cusror) in Redis. If the start_id
+    # It saves the cursor of the next start_id (cursor) in Redis. If the start_id
     # wasn't saved in Redis, for example, in the first run, it will choose some random start_id
     #
     # Example:
diff --git a/spec/services/database/consistency_check_service_spec.rb b/spec/services/database/consistency_check_service_spec.rb
index 8b7560f80ad04..af6cc367cb6f1 100644
--- a/spec/services/database/consistency_check_service_spec.rb
+++ b/spec/services/database/consistency_check_service_spec.rb
@@ -83,10 +83,10 @@
         create_list(:namespace, 50) # This will also create Ci::NameSpaceMirror objects
       end
 
-      it 'picks a random start_id' do
+      it 'picks a random start_id within the range of available item ids' do
         expected_result = {
-          batches: 2,
-          matches: 10,
+          batches: be_between(1, max_batches),
+          matches: be_between(1, max_batches * batch_size),
           mismatches: 0,
           mismatches_details: [],
           start_id: be_between(min_id, max_id),
-- 
GitLab