Speed project policy specs for both FOSS and EE
What does this MR do?
Reuse factories (already let_it_be
) from shared context where
feasible.
This is a follow-up of !38185 (merged).
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
for both spec files combined. Note:
-
Total
amount of factories created went down from 717 to 363🚀 -
Total events
went down from 77008 to 13266 - Queries saved: 63742
- Spec runtime went down from ~3m to ~45s
Before
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 01:31.023 of 02:51.087 (53.2%)
Total events: 77008
Top 5 slowest suites (by time):
ProjectPolicy (./spec/policies/project_policy_spec.rb:5) – 01:13.350 (62579 / 248) of 02:14.244 (54.64%)
ProjectPolicy (./ee/spec/policies/project_policy_spec.rb:5) – 00:17.672 (14429 / 359) of 00:36.842 (47.97%)
Finished in 2 minutes 58.2 seconds (files took 2.42 seconds to load)
607 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 717
Total top-level: 561
Total time: 54.1749s
Total uniq factories: 19
total top-level total time time per call top-level time name
346 334 47.0931s 0.1361s 44.7087s project
135 107 5.1151s 0.0379s 4.0435s user
107 0 4.5936s 0.0429s 0.0000s namespace
41 33 1.0950s 0.0267s 0.9452s group
20 20 0.1073s 0.0054s 0.1073s deploy_token
10 10 0.3105s 0.0310s 0.3105s admin
8 8 0.6034s 0.0754s 0.6034s group_member
8 8 0.0807s 0.0101s 0.0807s saml_provider
8 8 0.0716s 0.0090s 0.0716s group_saml_identity
8 8 1.4939s 0.1867s 1.4939s push_rule_sample
6 6 0.1304s 0.0217s 0.1304s project_deploy_token
4 4 0.0172s 0.0043s 0.0172s ip_restriction
4 4 0.9950s 0.2487s 0.9950s push_rule
4 4 0.0305s 0.0076s 0.0305s push_rule_without_project
3 3 0.4423s 0.1474s 0.4423s merge_request
2 2 0.0112s 0.0056s 0.0112s license
1 1 0.0842s 0.0842s 0.0842s issue
1 1 0.0994s 0.0994s 0.0994s jira_service
1 0 0.0243s 0.0243s 0.0000s jira_tracker_data
After
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:16.005 of 00:37.526 (42.65%)
Total events: 13266
Top 5 slowest suites (by time):
ProjectPolicy (./ee/spec/policies/project_policy_spec.rb:5) – 00:08.285 (6663 / 359) of 00:19.625 (42.21%)
ProjectPolicy (./spec/policies/project_policy_spec.rb:5) – 00:07.720 (6603 / 248) of 00:17.900 (43.13%)
Finished in 45.91 seconds (files took 2.41 seconds to load)
607 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 363
Total top-level: 269
Total time: 16.1768s
Total uniq factories: 22
total top-level total time time per call top-level time name
124 93 4.6447s 0.0375s 3.5899s user
67 55 9.1722s 0.1369s 7.3440s project
41 33 1.0283s 0.0251s 0.8693s group
38 0 1.5408s 0.0405s 0.0000s namespace
20 20 0.1413s 0.0071s 0.1413s deploy_token
10 10 0.3278s 0.0328s 0.3278s admin
8 8 0.6293s 0.0787s 0.6293s group_member
8 8 0.0805s 0.0101s 0.0805s saml_provider
8 8 0.1659s 0.0207s 0.1659s group_saml_identity
8 8 1.3025s 0.1628s 1.3025s push_rule_sample
6 6 0.0524s 0.0087s 0.0524s project_deploy_token
4 4 0.0269s 0.0067s 0.0269s ip_restriction
4 4 0.6126s 0.1531s 0.6126s push_rule
4 4 0.0287s 0.0072s 0.0287s push_rule_without_project
3 3 0.4325s 0.1442s 0.4325s merge_request
3 1 0.3696s 0.1232s 0.2885s cluster
2 2 0.0178s 0.0089s 0.0178s license
1 1 0.0762s 0.0762s 0.0762s issue
1 1 0.1906s 0.1906s 0.1906s jira_service
1 0 0.0941s 0.0941s 0.0000s jira_tracker_data
1 0 0.0505s 0.0505s 0.0000s cluster_provider_gcp
1 0 0.1077s 0.1077s 0.0000s cluster_platform_kubernetes
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