Skip to content

Speed up deployment entity spec

What does this MR do and why?

This MR improves runtime of deployment entity spec by using before_all and let_it_be where possible.

Closes #374540 (closed).

Refs &8745.

RSpec Profiling

Here's the output from test-prof when run with FPROF=1. Note:

  • Total amount of factories created went down from 207 to 19 🚀
  • Total events went down from 7649 to 1111
  • Queries saved: 6538

Before

Finished in 53.18 seconds (files took 6.16 seconds to load)
19 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:29.270 (54.39% of total time)
[TEST PROF INFO] Factories usage

 Total: 207
 Total top-level: 118
 Total time: 00:29.270 (out of 00:57.582)
 Total uniq factories: 8

   total   top-level     total time      time per call      top-level time               name

      41          17       24.0881s            0.5875s            10.2939s            project
      41           0        4.3990s            0.1073s             0.0000s          namespace
      38          38        3.1733s            0.0835s             3.1733s               user
      23          23       14.3467s            0.6238s            14.3467s         deployment
      23           0       13.8470s            0.6020s             0.0000s        environment
      22          22        1.0202s            0.0464s             1.0202s           ci_build
      18          17        0.6504s            0.0361s             0.4235s        ci_pipeline
       1           1        0.0129s            0.0129s             0.0129s            license

After

Finished in 14.74 seconds (files took 6.43 seconds to load)
13 examples, 0 failures

Randomized with seed 32310

[TEST PROF INFO] Time spent in factories: 00:01.594 (10.36% of total time)
[TEST PROF INFO] Factories usage

 Total: 19
 Total top-level: 18
 Total time: 00:01.594 (out of 00:19.336)
 Total uniq factories: 8

   total   top-level     total time      time per call      top-level time               name

       9           9        0.3103s            0.0345s             0.3103s           ci_build
       3           3        0.0568s            0.0189s             0.0568s         deployment
       2           2        0.4063s            0.2031s             0.4063s               user
       1           1        0.0112s            0.0112s             0.0112s            license
       1           1        0.7279s            0.7279s             0.7279s            project
       1           0        0.0617s            0.0617s             0.0000s          namespace
       1           1        0.0174s            0.0174s             0.0174s        environment
       1           1        0.0649s            0.0649s             0.0649s        ci_pipeline

How to set up and validate locally

bin/rspec spec/serializers/deployment_entity_spec.rb

MR acceptance checklist

This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.

Edited by Peter Leitzen

Merge request reports