Optimize factory usage for identifier_entity_spec
What does this MR do and why?
This MR replaces create with build_stubbed in ee/spec/serializers/vulnerabilities/identifier_entity_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 ee/spec/serializers/vulnerabilities/identifier_entity_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 1.484s (2.24% of total time)
After optimization:
- Factory time: 0.045s (0.27% of total time)
- Factory time reduced by: 1.439s
- Factory time percentage reduced by: 1.97%
- Overall factory usage improvement: 97.0%
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
==> Go projects set up in 0.792 seconds...
Test environment set up in 2.2111429999931715 seconds
.[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 1
Total wasted time: 00:01.393
Vulnerabilities::IdentifierEntity (./ee/spec/serializers/vulnerabilities/identifier_entity_spec.rb:5) (4 records created, 00:01.393)
contains required fields (./ee/spec/serializers/vulnerabilities/identifier_entity_spec.rb:15) – 4 records created, 00:01.393
Finished in 13.98 seconds (files took 16.03 seconds to load)
1 example, 0 failures
Randomized with seed 26540
[TEST PROF INFO] Time spent in factories: 00:01.404 (7.72% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.045 (0.27% 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.