Speed up project policy specs by using `before_all`
What does this MR do and why?
This MR improves spec runtime of project policy spec by using before_all
+ reusing existing variables avoiding SQL queries.
Improvement found while reviewing !98007 (merged).
Contributes to #374085 (closed) and &8584 (closed).
RSpec Profiling
Here's the output from test-prof
when run with FPROF=1
. Note:
-
Total amount
of factories created went down from 389 to 370🚀 -
Total events
went down from 29015 to 19079 - Queries saved: 9936
Before
Finished in 1 minute 53.38 seconds (files took 15.76 seconds to load)
863 examples, 0 failures
Randomized with seed 48898
[TEST PROF INFO] Time spent in factories: 00:26.969 (21.93% of total time)
[TEST PROF INFO] Factories usage
Total: 389
Total top-level: 285
Total time: 00:26.969 (out of 02:07.277)
Total uniq factories: 21
total top-level total time time per call top-level time name
119 103 9.9301s 0.0834s 8.7979s user
61 61 14.3411s 0.2351s 14.3411s project
46 1 4.2100s 0.0915s 0.0844s namespace
40 40 0.2570s 0.0064s 0.2570s deploy_token
33 33 0.2370s 0.0072s 0.2370s project_deploy_token
17 13 1.0931s 0.0643s 0.8721s group
17 0 0.0750s 0.0044s 0.0000s namespace_settings
17 0 0.0644s 0.0038s 0.0000s namespace_ci_cd_settings
9 9 0.2492s 0.0277s 0.2492s deploy_key
6 6 0.0479s 0.0080s 0.0479s deploy_keys_project
5 5 0.1429s 0.0286s 0.1429s ci_pipeline
4 4 0.6462s 0.1616s 0.6462s group_member
3 3 0.2451s 0.0817s 0.2451s admin
3 1 0.4423s 0.1474s 0.3042s cluster
3 3 0.3443s 0.1148s 0.3443s merge_request
1 1 0.0092s 0.0092s 0.0092s license
1 1 0.2441s 0.2441s 0.2441s issue
1 0 0.0147s 0.0147s 0.0000s work_item_type
1 0 0.0914s 0.0914s 0.0000s cluster_provider_gcp
1 0 0.1040s 0.1040s 0.0000s cluster_platform_kubernetes
1 1 0.1467s 0.1467s 0.1467s jira_integration
After
Finished in 1 minute 30.32 seconds (files took 6.92 seconds to load)
857 examples, 0 failures
Randomized with seed 56046
[TEST PROF INFO] Time spent in factories: 00:30.312 (33.19% of total time)
[TEST PROF INFO] Factories usage
Total: 370
Total top-level: 272
Total time: 00:30.312 (out of 01:35.340)
Total uniq factories: 21
total top-level total time time per call top-level time name
108 94 10.8697s 0.1006s 9.5582s user
58 58 15.9172s 0.2744s 15.9172s project
44 1 5.0956s 0.1158s 0.0900s namespace
40 40 0.3250s 0.0081s 0.3250s deploy_token
33 33 0.5592s 0.0169s 0.5592s project_deploy_token
16 12 1.0572s 0.0661s 0.7777s group
16 0 0.0747s 0.0047s 0.0000s namespace_settings
16 0 0.0685s 0.0043s 0.0000s namespace_ci_cd_settings
9 9 0.2869s 0.0319s 0.2869s deploy_key
6 6 0.0475s 0.0079s 0.0475s deploy_keys_project
5 5 0.1455s 0.0291s 0.1455s ci_pipeline
4 4 0.8596s 0.2149s 0.8596s group_member
3 3 0.2445s 0.0815s 0.2445s admin
3 3 0.4572s 0.1524s 0.4572s merge_request
3 1 0.8671s 0.2890s 0.6397s cluster
1 1 0.0068s 0.0068s 0.0068s license
1 1 0.2662s 0.2662s 0.2662s issue
1 0 0.0153s 0.0153s 0.0000s work_item_type
1 1 0.1311s 0.1311s 0.1311s jira_integration
1 0 0.1443s 0.1443s 0.0000s cluster_provider_gcp
1 0 0.2835s 0.2835s 0.0000s cluster_platform_kubernetes
How to set up and validate locally
bin/rspec spec/policies/project_policy_spec.rb
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.
Edited by Peter Leitzen