Optimize factory usage for service hook presenter
What does this MR do and why?
This MR replaces create with build_stubbed in spec/presenters/service_hook_presenter_spec.rb to optimize the factory usage as recommended in our handbook.
This spec is part of the list .rubocop_todo/rspec/factory_bot/avoid_create.yml.
It was verified that database persistence is not needed using the factory doctor command FDOC=1 bin/rspec spec/presenters/service_hook_presenter_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 1.77s (9.67% of total time)
After optimization:
- Factory time: 0.042s (0.25% of total time)
- Factory time reduced by: 1.728s
- Factory time percentage reduced by: 9.42%
- Overall factory usage improvement: 97.6%
Factory Doctor Output
[TEST PROF INFO] FactoryDoctor enabled (event: "sql.active_record", threshold: 0.01)
Run options: include {:focus=>true}
All examples were filtered out; ignoring {:focus=>true}
==> Using precompiled Gitaly binaries from cache
Test environment set up in 1.0891780000019935 seconds
..[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 2
Total wasted time: 00:01.953
ServiceHookPresenter (./spec/presenters/service_hook_presenter_spec.rb:5) (12 records created, 00:01.953)
is expected to eq "/namespace1/project-1/-/settings/integrations/drone_ci/hook_logs/3/retry" (./spec/presenters/service_hook_presenter_spec.rb:28) – 6 records created, 00:01.598
is expected to eq "/namespace2/project-2/-/settings/integrations/drone_ci/hook_logs/4" (./spec/presenters/service_hook_presenter_spec.rb:18) – 6 records created, 00:00.354
Finished in 15.18 seconds (files took 13.58 seconds to load)
2 examples, 0 failures
Randomized with seed 44566
[TEST PROF INFO] Time spent in factories: 00:01.959 (10.47% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.042 (0.25% of total time)References
Relates to: #378910.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.