Speed up merge request presenter specs
What does this MR do?## What does this MR do?
This MR improves the performance of merge request presenter specs by using let_it_be
and before_all
where applicable.
Related to &3752.
Contributes to https://gitlab.com/gitlab-org/plan/-/issues/145.
Here's the output from test-prof
when run with FPROF=1
. Note:
-
Total
amount of factories created went down from 219 to 18🚀 -
Total events
went down from 7515 to 1171 - Queries saved: 6344
Before
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:10.822 of 00:25.292 (42.79%)
Total events: 7515
Top 5 slowest suites (by time):
MergeRequestPresenter (./spec/presenters/merge_request_presenter_spec.rb:5) – 00:10.822 (7515 / 51) of 00:25.292 (42.79%)
Finished in 32.56 seconds (files took 27.95 seconds to load)
51 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 219
Total top-level: 171
Total time: 20.1336s
Total uniq factories: 6
total top-level total time time per call top-level time name
54 51 10.4262s 0.1931s 9.6260s project
51 51 6.5558s 0.1285s 6.5558s merge_request
47 47 2.1603s 0.0460s 2.1603s user
45 0 2.1053s 0.0468s 0.0000s namespace
21 21 1.7829s 0.0849s 1.7829s issue
1 1 0.0086s 0.0086s 0.0086s license
After
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:01.677 of 00:07.915 (21.19%)
Total events: 1171
Top 5 slowest suites (by time):
MergeRequestPresenter (./spec/presenters/merge_request_presenter_spec.rb:5) – 00:01.677 (1171 / 51) of 00:07.915 (21.19%)
Finished in 13.55 seconds (files took 2.1 seconds to load)
51 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 18
Total top-level: 11
Total time: 3.0930s
Total uniq factories: 6
total top-level total time time per call top-level time name
5 2 1.3198s 0.2640s 0.7580s project
5 5 0.7960s 0.1592s 0.7960s issue
4 0 0.2247s 0.0562s 0.0000s namespace
2 2 1.4895s 0.7447s 1.4895s merge_request
1 1 0.0111s 0.0111s 0.0111s license
1 1 0.0384s 0.0384s 0.0384s user
Does this MR meet the acceptance criteria?
Conformity
- [-] Changelog entry
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Availability and Testing
-
Review and add/update tests for this feature/bug. Consider all test levels. See the Test Planning Process. - [-] Tested in all supported browsers
- [-] Informed Infrastructure department of a default or new setting change, if applicable per definition of done
Security
If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:
- [-] Label as security and @ mention
@gitlab-com/gl-security/appsec
- [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
- [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Peter Leitzen