Improve performance of groups helper spec
What does this MR do?
This MR improves performance for groups helper spec by using let_it_be
or build_stubbed
where feasible.
Inspiration for this MR came up during review of !57007 (merged).
RSpec Profiling
Here's the output from test-prof
when run with FPROF=1
. Note:
-
Total amount
of factories created went down from 342 to 61🚀 -
Total events
went down from 7941 to 2404 - Queries saved: 5537
Before
[TEST PROF INFO] FactoryDoctor enabled (event: "sql.active_record", threshold: 0.01)
[TEST PROF INFO] FactoryProf enabled (simple mode)
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
.............................................................................[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 11
Total wasted time: 00:01.232
GroupsHelper (./spec/helpers/groups_helper_spec.rb:5) (36 records created, 00:01.232)
converts uppercase letters to lowercase (./spec/helpers/groups_helper_spec.rb:26) – 2 records created, 00:00.024
is expected to be truthy (./spec/helpers/groups_helper_spec.rb:228) – 3 records created, 00:00.072
is disabled for guest (./spec/helpers/groups_helper_spec.rb:230) – 3 records created, 00:00.071
is expected to be falsy (./spec/helpers/groups_helper_spec.rb:241) – 3 records created, 00:00.068
is disabled for guests (./spec/helpers/groups_helper_spec.rb:243) – 3 records created, 00:00.071
returns true for the group owner (./spec/helpers/groups_helper_spec.rb:332) – 3 records created, 00:00.543
returns false for anyone else (./spec/helpers/groups_helper_spec.rb:338) – 3 records created, 00:00.061
returns false if parent group is disabling emails (./spec/helpers/groups_helper_spec.rb:349) – 5 records created, 00:00.101
returns true if parent group is not disabling emails (./spec/helpers/groups_helper_spec.rb:355) – 5 records created, 00:00.099
is expected to be truthy (./spec/helpers/groups_helper_spec.rb:378) – 3 records created, 00:00.057
is expected to be falsey (./spec/helpers/groups_helper_spec.rb:386) – 3 records created, 00:00.059
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:09.460 of 00:28.736 (32.92%)
Total events: 7941
Top 5 slowest suites (by time):
GroupsHelper (./spec/helpers/groups_helper_spec.rb:5) – 00:09.460 (7941 / 77) of 00:28.736 (32.92%)
Finished in 37.75 seconds (files took 11.25 seconds to load)
77 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 342
Total top-level: 218
Total time: 10.2640s
Total uniq factories: 6
total top-level total time time per call top-level time name
114 114 4.4950s 0.0394s 4.4950s group
114 0 0.4043s 0.0035s 0.0000s namespace_settings
93 93 4.2742s 0.0460s 4.2742s user
10 10 1.4829s 0.1483s 1.4829s project
10 0 0.4296s 0.0430s 0.0000s namespace
1 1 0.0119s 0.0119s 0.0119s license
After
[TEST PROF INFO] FactoryDoctor enabled (event: "sql.active_record", threshold: 0.01)
[TEST PROF INFO] FactoryProf enabled (simple mode)
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (sql.active_record)
.............................................................................[TEST PROF INFO] FactoryDoctor says: "Looks good to me!"
[TEST PROF INFO] EventProf results for sql.active_record
Total time: 00:03.228 of 00:16.617 (19.43%)
Total events: 2404
Top 5 slowest suites (by time):
GroupsHelper (./spec/helpers/groups_helper_spec.rb:5) – 00:03.228 (2404 / 77) of 00:16.617 (19.43%)
Finished in 25.46 seconds (files took 13.69 seconds to load)
77 examples, 0 failures
[TEST PROF INFO] Factories usage
Total: 61
Total top-level: 37
Total time: 2.2997s
Total uniq factories: 6
total top-level total time time per call top-level time name
22 22 1.2379s 0.0563s 1.2379s group
22 0 0.0839s 0.0038s 0.0000s namespace_settings
12 12 0.4261s 0.0355s 0.4261s user
2 2 0.6249s 0.3124s 0.6249s project
2 0 0.1357s 0.0679s 0.0000s namespace
1 1 0.0107s 0.0107s 0.0107s license
Does this MR meet the acceptance criteria?
Conformity
-
📋 Does this MR need a changelog?- [-] I have included a changelog entry.
-
I have not included a changelog entry because it's developer-facing change.
- [-] Documentation (if required)
-
Code review guidelines -
Merge request performance guidelines -
Style guides - [-] Database guides
- [-] Separation of EE specific content
Edited by Peter Leitzen