Reduce a number of projects created in specs to speed things up
I created https://gitlab.com/gitlab-org/gitlab-ce/merge_requests/13875 to check which specs create what number of projects. Creating a project in specs, even if it has no :repository
trait means that we have to execute bunch of database queries.
These are some results:
391 ./spec/services/system_note_service_spec.rb
356 ./spec/support/notify_shared_examples.rb
322 ./spec/requests/api/projects_spec.rb
271 ./spec/models/project_spec.rb
251 ./spec/services/auth/container_registry_authentication_service_spec.rb
241 ./spec/requests/api/v3/projects_spec.rb
240 ./spec/lib/gitlab/import_export/project_tree_saver_spec.rb
237 ./spec/models/repository_spec.rb
219 ./spec/factories_spec.rb
194 ./spec/requests/api/services_spec.rb
194 ./spec/models/ci/build_spec.rb
181 ./spec/requests/api/groups_spec.rb
178 ./spec/requests/api/v3/groups_spec.rb
163 ./spec/requests/api/v3/issues_spec.rb
159 ./spec/services/ci/retry_build_service_spec.rb
157 ./spec/requests/lfs_http_spec.rb
152 ./spec/models/concerns/has_status_spec.rb
142 ./spec/features/markdown_spec.rb
133 ./spec/requests/api/v3/notes_spec.rb
133 ./spec/requests/api/notes_spec.rb
133 ./spec/requests/api/merge_requests_spec.rb
130 ./spec/services/issues/move_service_spec.rb
129 ./spec/services/quick_actions/interpret_service_spec.rb
123 ./spec/lib/gitlab/closing_issue_extractor_spec.rb
122 ./spec/support/shared_examples/requests/api/status_shared_examples.rb
117 ./spec/services/notification_service_spec.rb
116 ./spec/support/taskable_shared_examples.rb
116 ./spec/requests/git_http_spec.rb
116 ./spec/lib/gitlab/git_access_spec.rb
105 ./spec/requests/api/todos_spec.rb
105 ./spec/lib/banzai/filter/label_reference_filter_spec.rb
103 ./spec/requests/api/runner_spec.rb
100 ./spec/support/email_format_shared_examples.rb
I tried to optimize system_note_service_spec.rb
and using set(:project) { ... }
in a few places has cut execution time by half.
Before:
Finished in 1 minute 26.13 seconds (files took 20.05 seconds to load)
330 examples, 0 failures
["391 ./spec/services/system_note_service_spec.rb"]
After:
Finished in 49.93 seconds (files took 16.61 seconds to load)
330 examples, 0 failures
["75 ./spec/services/system_note_service_spec.rb"]
It might make sense to check optimize more specs, and check number of INSERTs in the CI to fail a job when the number is too high.
What do you think @rymai @rspeicher?