Speed up specs for merge request approval state
What does this MR do?
This MR improves the performance of merge request approval state specs by using let_it_be
and before_all
where applicable.
Related to &3752.
Contributes to https://gitlab.com/gitlab-org/plan/-/issues/145 and also to #220040 (closed) (
Here's the output from test-prof
when run with FPROF=1
. Note:
-
Total
amount of factories created went down from 1537 to 549🚀 -
Total events
went down from 41282 to 8486 - Queries saved: 32796
Before
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:59.489 of 02:07.932 (46.5%)
Total events: 41282
Top 5 slowest suites (by time):
ApprovalState (./ee/spec/models/approval_state_spec.rb:5) – 00:59.489 (41282 / 198) of 02:07.932 (46.5%)
Finished in 2 minutes 15.6 seconds (files took 2.5 seconds to load)
198 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 1537
Total top-level: 1213
Total time: 102.9216s
Total uniq factories: 14
total top-level total time time per call top-level time name
567 553 22.9800s 0.0405s 22.2560s user
198 198 57.3505s 0.2896s 57.3505s merge_request
198 93 38.1178s 0.1925s 17.4571s project
198 0 9.5508s 0.0482s 0.0000s namespace
143 143 1.7644s 0.0123s 1.7644s approval_merge_request_rule
70 70 0.8063s 0.0115s 0.8063s approval
52 52 0.5921s 0.0114s 0.5921s approval_project_rule
28 28 0.4625s 0.0165s 0.4625s any_approver_rule
24 24 0.2828s 0.0118s 0.2828s code_owner_rule
24 24 0.2695s 0.0112s 0.2695s report_approver_rule
19 12 0.5342s 0.0281s 0.2870s group
8 8 0.2449s 0.0306s 0.2449s protected_branch
7 7 1.1268s 0.1610s 1.1268s group_member
1 1 0.0215s 0.0215s 0.0215s license
After
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:12.165 of 00:25.870 (47.03%)
Total events: 8486
Top 5 slowest suites (by time):
ApprovalState (./ee/spec/models/approval_state_spec.rb:5) – 00:12.165 (8486 / 198) of 00:25.870 (47.03%)
Finished in 32.74 seconds (files took 2.66 seconds to load)
198 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 445
Total top-level: 421
Total time: 12.0361s
Total uniq factories: 14
total top-level total time time per call top-level time name
143 143 2.8017s 0.0196s 2.8017s approval_merge_request_rule
70 70 0.8003s 0.0114s 0.8003s approval
65 51 2.7323s 0.0420s 2.1488s user
52 52 0.5514s 0.0106s 0.5514s approval_project_rule
28 28 0.6390s 0.0228s 0.6390s any_approver_rule
24 24 0.3689s 0.0154s 0.3689s code_owner_rule
24 24 0.3985s 0.0166s 0.3985s report_approver_rule
14 7 0.4444s 0.0317s 0.1852s group
8 8 0.1408s 0.0176s 0.1408s protected_branch
7 7 0.9569s 0.1367s 0.9569s group_member
3 3 1.2435s 0.4145s 1.2435s project
3 0 0.2352s 0.0784s 0.0000s namespace
3 3 1.7910s 0.5970s 1.7910s merge_request
1 1 0.0098s 0.0098s 0.0098s license
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