Skip to content

Reduce usages of `let(:project)`

Summary

The :project factory is one of the most used and simultaneously one of the most expensive test factories. It takes approximately 50 SQL queries to create a project, and the time taken to create projects seems to have a compounding effect with the number of projects being created in a single spec.

Searching gitlab-org/gitlab specs shows that we have ~2900 instances of let_it_be(:project) and ~3700 instances of let(:project). Projects are persistent objects by nature (how many times in your usage of GitLab have you ever had to delete a project?), so I would think that the large majority of these specs don't actually have to create new projects for each example. Paying special attention to instances of let(:project) and discouraging its use seems like the easiest way to speed up our tests and pipelines.

Proposal

  1. Add automated code review comments discouraging the usage of let with the :project factory, similar to our suggestion to use match_array
  2. Find the top specs (by number of examples) using let(:project) and try to convert them to let_it_be

MR Label

Make sure to add rspec profiling to MRs which improve RSpec runtime so they appear on https://gitlab-org.gitlab.io/rspec_profiling_stats/#queries.

Prior discussions

https://gitlab.com/gitlab-org/plan/-/issues/145

Edited by Peter Leitzen