Skip to content

Fix flaky test "#protected_branch_exists?"

Vasilii Iakliushin requested to merge 470324_fix_flaky_test into master

What does this MR do and why?

Contributes to #470324 (closed)

Call to all_protected_branches is cached and not reloaded between consecutive tests.

let_it_be_with_reload forces project to refresh associations.

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.

Screenshots or screen recordings

Before

bundle exec rspec --format documentation spec/services/projects/protect_default_branch_service_spec.rb:259
Run options: include {:focus=>true, :locations=>{"./spec/services/projects/protect_default_branch_service_spec.rb"=>[259]}}

Test environment set up in 2.311242 seconds

Projects::ProtectDefaultBranchService
  #protected_branch_exists?
    when feature flag `group_protected_branches` disabled
      return false
    when feature flag `group_protected_branches` enabled
      return true (FAILED - 1)

Failures:

  1) Projects::ProtectDefaultBranchService#protected_branch_exists? when feature flag `group_protected_branches` enabled return true
     Failure/Error: expect(service.protected_branch_exists?).to eq(true)

       expected: true
            got: false

       (compared using ==)

       Diff:
       @@ -1 +1 @@
       -true
       +false

After

bundle exec rspec --format documentation spec/services/projects/protect_default_branch_service_spec.rb:259
Run options: include {:focus=>true, :locations=>{"./spec/services/projects/protect_default_branch_service_spec.rb"=>[259]}}

Test environment set up in 2.383773 seconds

Projects::ProtectDefaultBranchService
  #protected_branch_exists?
    when feature flag `group_protected_branches` disabled
      return false
    when feature flag `group_protected_branches` enabled
      return true

Finished in 6.27 seconds (files took 17.19 seconds to load)
2 examples, 0 failures

How to set up and validate locally

  1. bundle exec rspec --format documentation spec/services/projects/protect_default_branch_service_spec.rb:259

Merge request reports

Loading