Improve slow tests in ./ee/spec/features/search/elastic/project_search_spec.rb

Summary

The total running time of ./ee/spec/features/search/elastic/project_search_spec.rb is 1541.24 seconds and it executes 10541 queries. It is likely this can be improved. Please review this suite or example for opportunities to fix slow tests.

Description

This issue was generated from the rspec profiling project which profiles rspec tests in pipelines run against the default branch on gitlab-org/gitlab.

How to improve this test?

Please follow our testing best practices to speed up tests at https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#test-speed.

Search specific suggestions

  1. move all factory creates to let_it_be, this required using Elastic::ProcessInitialBookkeeping.track! methods to be added. I've found this is a good way to avoid recreating data for every test
  2. remove sidekiq_inline unless testing git backed data: commits, blobs, and wikis
  3. move extremely slow context or describe blocks into their own spec file: Example: ee/spec/services/search/group_service_wiki_visibility_spec.rb
  4. (optional) fix Rubocop TODOs
  5. (optional) if test order is exempt from running in random. check if it can be enabled by following https://docs.gitlab.com/ee/development/testing_guide/best_practices.html#test-order