Optimize factory usage for web ide terminal entity
What does this MR do and why?
This MR replaces create with build_stubbed in spec/serializers/web_ide_terminal_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 spec/serializers/web_ide_terminal_entity_spec.rb.
Factory Usage Optimization Results
Before optimization:
- Factory time: 3.795s (5.23% of total time)
After optimization:
- Factory time: 0.1s (0.56% of total time)
- Factory time reduced by: 3.695s
- Factory time percentage reduced by: 4.67%
- Overall factory usage improvement: 97.4%
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.2193949999928009 seconds
.........[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 9
Total wasted time: 00:04.130
WebIdeTerminalEntity (./spec/serializers/web_ide_terminal_entity_spec.rb:5) (45 records created, 00:04.130)
is expected to have key :id (./spec/serializers/web_ide_terminal_entity_spec.rb:11) – 5 records created, 00:01.617
is expected to have key :status (./spec/serializers/web_ide_terminal_entity_spec.rb:12) – 5 records created, 00:00.285
is expected to have key :show_path (./spec/serializers/web_ide_terminal_entity_spec.rb:13) – 5 records created, 00:00.272
is expected to have key :cancel_path (./spec/serializers/web_ide_terminal_entity_spec.rb:14) – 5 records created, 00:00.249
is expected to have key :retry_path (./spec/serializers/web_ide_terminal_entity_spec.rb:15) – 5 records created, 00:00.459
is expected to have key :terminal_path (./spec/serializers/web_ide_terminal_entity_spec.rb:16) – 5 records created, 00:00.262
is expected to have key :services (./spec/serializers/web_ide_terminal_entity_spec.rb:17) – 5 records created, 00:00.266
is expected to have key :proxy_websocket_path (./spec/serializers/web_ide_terminal_entity_spec.rb:18) – 5 records created, 00:00.256
is expected not to have key :proxy_websocket_path (./spec/serializers/web_ide_terminal_entity_spec.rb:25) – 5 records created, 00:00.460
Finished in 17.21 seconds (files took 14.81 seconds to load)
9 examples, 0 failures
[TEST PROF INFO] Time spent in factories: 00:04.136 (19.0% of total time)
Factory time before the update
[TEST PROF INFO] Time spent in factories: 00:03.795 (5.23% of total time)
Factory time after update
[TEST PROF INFO] Time spent in factories: 00:00.100 (0.56% of total time)
This MR also adds the missing feature category in this spec.
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.