Skip to content

Fixing Flaky Test in ConsistencyCheckService

What does this MR do and why?

Fixing Flaky Test in ConsistencyCheckService

Addressing: #450478 (closed)

More Context

We mirror some data from the main database to the ci database. We use a Consistency Check Service that regularly checks for the data consistency, and saves the cursor in Redis.

If the cursor wasn't not there for some reason, we start scanning from a random ID, to avoid always scanning from 0.

This MR fixes a flaky tests, in which it wasn't considered that this random ID can be at the end of the range. Therefore the number of matches items doesn't equal to 10. See a an example of a failed test

Test locally

Change the random_start_id in app/services/database/consistency_check_service.rb to return an ID at the end of the range. For example:

    def random_start_id
      range_start = min_id
      range_end = [min_id, max_id - Gitlab::Database::ConsistencyChecker::BATCH_SIZE].max
      rand(range_start..range_end) <-- We still need this line for a test to pass

      return max_id - 3
    end

The test will still pass now.

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Related to #450478 (closed)

Edited by Omar Qunsul

Merge request reports

Loading