Improve Deployments and Size quota specs for clarity and consistency
What does this MR do and why?
Improves the Gitlab::Ci::Pipeline::Quota::Deployments and Gitlab::Ci::Pipeline::Quota::Size specs for clarity and consistency.
Note: The flakiness was already addressed in !223864 (merged). This MR focuses on:
- Using
plan_limits.destroy!instead of stubbingactual_planto simulate "limit does not exist" — this is explicit about what "no limit" means and avoids relying on obscurePlan.new.actual_limitsbehavior (per @engwan's suggestion) - Using
let_it_be_with_refind(:plan_limits)— necessary becausedestroy!freezes the AR object, andrefindreturns a fresh object from DB each time (unlikereloadwhich mutates the same frozen object) - Ensuring consistency between both sister specs
- Removing
deployments_spec.rbfromrspec_order_todo.ymlsince it can now run in random order
Changes in deployments_spec.rb:
- Changed
let_it_be_with_refind(:namespace)tolet_it_be(:namespace)(simpler, no need for refind) - Added
let_it_be_with_refind(:plan_limits)that creates aPlanLimitsfor the default plan - Replaced
allow(namespace).to receive(:actual_plan).and_return(Plan.new)withplan_limits.destroy! - Removed from
rspec_order_todo.yml
Changes in size_spec.rb:
- Changed
let_it_be(:plan_limits, reload: true)tolet_it_be_with_refind(:plan_limits) - Replaced
allow(namespace).to receive(:actual_plan) { create(:default_plan) }withplan_limits.destroy!
References
- Related incident: https://app.incident.io/gitlab/incidents/7509
- Failing job: https://gitlab.com/gitlab-org/security/gitlab/-/jobs/13154657369
- Related MR that fixed the flakiness: !223864 (merged)
-
@engwan's suggestion to use
plan_limits.destroy!: !223864 (comment 3092145946)
Screenshots or screen recordings
Not applicable - test improvement only
How to set up and validate locally
-
Run both specs multiple times with random order:
for i in {1..10}; do bundle exec rspec spec/lib/gitlab/ci/pipeline/quota/deployments_spec.rb spec/lib/gitlab/ci/pipeline/quota/size_spec.rb --order random; done -
All runs should pass without failures.
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 Jorge Tomás