Skip to content

Refactor and speed up users API specs

Peter Leitzen requested to merge pl-spec-requests-api-users into master

What does this MR do?

This MR refactors and speeds up the requests API specs for users:

  • Prefer let_it_be over let! and over let where easily possible
  • Prefer update!
  • Skip .save for associations
  • Prefer non_existing_record_id or hardcoded numbers

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

  • Finished in improved by ~30 seconds 🚀
  • Total amount of factories created went down from 1019 to 425 🚀

Before

Finished in 1 minute 32.74 seconds (files took 1.7 seconds to load)
372 examples, 0 failures

Randomized with seed 18156

[TEST PROF INFO] Factories usage

 Total: 1019
 Total top-level: 973
 Total time: 38.8796s
 Total uniq factories: 15

   total   top-level   total time   top-level time                           name

     370         370      4.3315s          4.3315s          personal_access_token
     291         291     11.3835s         11.3835s                           user
     210         210      7.7174s          7.7174s                          admin
      20          20      0.6199s          0.6199s                            key
      19           8      2.9634s          1.1257s                        project
      18          18      0.8229s          0.8229s                  omniauth_user
      18           0      0.1393s          0.0000s                       identity
      18          18     10.3616s         10.3616s                        gpg_key
      18          18      0.1550s          0.1550s                          email
      17           0      0.6008s          0.0000s                      namespace
      11          11      2.2759s          2.2759s                          issue
       4           4      0.0227s          0.0227s                    user_status
       3           3      0.0530s          0.0530s                          group
       1           1      0.0070s          0.0070s                        license
       1           1      0.0037s          0.0037s                    user_detail

After

Finished in 1 minute 1.61 seconds (files took 1.67 seconds to load)
372 examples, 0 failures

Randomized with seed 7778

[TEST PROF INFO] Factories usage

 Total: 425
 Total top-level: 399
 Total time: 8.0219s
 Total uniq factories: 15

   total   top-level   total time   top-level time                           name

     330         330      3.3999s          3.3999s          personal_access_token
      26          26      1.1556s          1.1556s                           user
      18          18      0.9385s          0.9385s                  omniauth_user
      18           0      0.2301s          0.0000s                       identity
       9           8      1.4858s          1.2337s                        project
       7           0      0.2184s          0.0000s                      namespace
       4           4      0.1593s          0.1593s                          admin
       4           4      0.0418s          0.0418s                    user_status
       3           3      0.0627s          0.0627s                          group
       1           1      0.0069s          0.0069s                        license
       1           1      0.0340s          0.0340s                            key
       1           1      0.6447s          0.6447s                        gpg_key
       1           1      0.0174s          0.0174s                          email
       1           1      0.0064s          0.0064s                    user_detail
       1           1      0.3210s          0.3210s                          issue

Somehow related to #213649 (closed)

Does this MR meet the acceptance criteria?

Conformity

Availability and Testing

Security

If this MR contains changes to processing or storing of credentials or tokens, authorization and authentication methods and other items described in the security review guidelines:

  • [-] Label as security and @ mention @gitlab-com/gl-security/appsec
  • [-] The MR includes necessary changes to maintain consistency between UI, API, email, or other methods
  • [-] Security reports checked/validated by a reviewer from the AppSec team
Edited by Peter Leitzen

Merge request reports