Loading
Optimize factory usage in pipeline_artifact
What does this MR do and why?
This MR replaces create with build_stubbed in spec/models/ci/pipeline_artifact_spec.rb to optimize factory
usage as recommended in our handbook.
It was verified that database persistence is not needed using the factory doctor
command FDOC=1 bin/rspec spec/models/ci/pipeline_artifact_spec.rb.
build is used instead of build_stubbed where build_stubbed is not possible:
coverage_report: withbuild_stubbed, thevalidationsexamples fail withFile can't be blank, because the stubbed record does not keep the CarrierWave-mounted file thatvalidates :file, presence: truechecks.
Factory Usage Optimization Results
Before optimization:
- Factory time: 7.163s (32.85% of total time)
After optimization:
- Factory time: 5.552s (26.49% of total time)
Improvement:
- Factory time reduced by: 1.611s
- Factory time percentage reduced by: 6.36%
- Overall factory usage improvement: 22.49%
Estimated CI Cost Savings
Using the same methodology as !248403 (merged):
1.611s saved per pipeline × $0.03/minute (large runners: 3x cost factor on $10/1,000 base minutes).
| Scenario | Pipelines/month | Time saved/month | Savings/year |
|---|---|---|---|
| Pessimistic | 15,000 | 6.7h | $144.99 |
| Moderate | 30,000 | 13.4h | $289.98 |
| Optimistic | 50,000 | 22.4h | $483.30 |
Factory Doctor Output
[TEST PROF INFO] FactoryDoctor report
Total (potentially) bad examples: 11
Total wasted time: 00:04.436
Ci::PipelineArtifact (./spec/models/ci/pipeline_artifact_spec.rb:5) (55 records created, 00:04.436)
returns no errors (./spec/models/ci/pipeline_artifact_spec.rb:30) – 5 records created, 00:00.297
returns errors (./spec/models/ci/pipeline_artifact_spec.rb:36) – 5 records created, 00:00.302
returns errors (./spec/models/ci/pipeline_artifact_spec.rb:45) – 5 records created, 00:00.263
is stored locally (./spec/support/shared_examples/models/concerns/file_store_mounter_shared_examples.rb:4) – 5 records created, 00:00.498
is stored remotely (./spec/support/shared_examples/models/concerns/file_store_mounter_shared_examples.rb:12) – 5 records created, 00:00.484
sets the size in bytesize (./spec/models/ci/pipeline_artifact_spec.rb:124) – 5 records created, 00:00.403
returns true (./spec/models/ci/pipeline_artifact_spec.rb:161) – 5 records created, 00:00.338
returns true (./spec/models/ci/pipeline_artifact_spec.rb:179) – 5 records created, 00:00.444
uses code coverage presenter (./spec/models/ci/pipeline_artifact_spec.rb:359) – 5 records created, 00:00.746
uses code codequality mr diff presenter (./spec/models/ci/pipeline_artifact_spec.rb:367) – 5 records created, 00:00.363
assigns the same partition id as the one that pipeline has (./spec/models/ci/pipeline_artifact_spec.rb:390) – 5 records created, 00:00.292
47 examples, 0 failures
[TEST PROF INFO] Time spent in factories: 00:11.109 (25.43% of total time)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.