Skip to content

[rspec] Prevent duplicate calls to GroupDestroyWorker

Rutger Wessels requested to merge 469091-fix-flaky-groups-controller-specs into master

What does this MR do and why?

While working on #446293, I ran into an issue with ee/spec/controllers/ee/groups_controller_spec.rb. It sometimes failed

When the specs are run in random order, the specs can fail. The reason is because repeated calls to GroupDestroyWorker.perform_async, with the same arguments, are deduplicated. This will only be noticed if we explicitly test for GroupDestroyWorker.jobs.size.

The reason is setting idempotent! on the worker. I confirmed this by:

  • Calling the perform_async method with a different user_id, this will make the tests pass
  • Removing the idempotent! call, this will also make the test pass

This MR has two solutions:

  • If we call GroupDestroyWorker.perform_async, we can use a new user and group so the deduplication of the job does not happen
  • If we two tests that use the very same user and group, we can replace the two tests by one new tests

Although I ran into this with ee/spec/controllers/ee/groups_controller_spec.rb, spec/controllers/groups_controller_spec.rb had the same problem. So fixing that as well

Related to #469091

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.

How to set up and validate locally

  • Run bundle exec rspec --seed 34269 ee/spec/controllers/ee/groups_controller_spec.rb on master branch, it will fail
  • Run bundle exec rspec --seed 55997 spec/controllers/groups_controller_spec.rb on master, it will fail
  • Switch to this branch and run the specs again. They should pass
Edited by Rutger Wessels

Merge request reports

Loading