Flaky Test: Fix AtomicInternalId flakiness in Deployment spec by shadowing project scope

What does this MR do and why?

The 'AtomicInternalId' shared example in deployment_spec.rb was flaky, intermittently failing with ActiveRecord::RecordNotUnique on the index_deployments_on_project_id_and_iid unique constraint.

This occurred because the shared example was using the same project instance that had other Deployment records (and thus InternalId state for deployments) created by top-level let_it_be blocks in the spec file. When the shared example attempted to generate IIDs for its new Deployment instance within this pre-populated project scope, it could lead to IID collisions if the AtomicInternalId's init logic re-calculated the starting IID based on existing records in a way that conflicted with already assigned IIDs (especially iid=1).

This commit fixes the flakiness by providing a dedicated, fresh Project instance (iid_test_project) and its associated Environment and Deployable specifically for the context of the it_behaves_like 'AtomicInternalId' block. This ensures that the IID generation tests within the shared example operate in a clean, isolated scope, preventing collisions with IIDs from other test setup.

References

#505439 (closed)

Screenshots or screen recordings

N/A

How to set up and validate locally

  1. Check out this branch.
  2. Run the deployment_spec.rb file multiple times:
    bundle exec rspec spec/models/deployment_spec.rb --order random
  3. The test should now pass consistently.

MR acceptance checklist

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

Edited by Zakaria Fatahi

Merge request reports

Loading