Skip to content

Optimize factory usage in search specs

Dmitry Gruzd requested to merge 321017-optimize-factory-usage into master

What does this MR do?

This is a follow up from !53589 (merged) to improve factory usage in some search specs.

#321017 (closed)

Before

EVENT_PROF="factory.create" bin/rspec spec/lib/gitlab/search_results_spec.rb spec/services/search/global_service_spec.rb spec/services/search/group_service_spec.rb ee/spec/services/search/project_service_spec.rb ee/spec/services/search/global_service_spec.rb ee/spec/lib/gitlab/elastic/search_results_spec.rb ee/spec/services/search/group_service_spec.rb

...

[TEST PROF INFO] EventProf results for factory.create

Total time: 06:38.794 of 28:48.017 (23.08%)
Total events: 5566

Finished in 28 minutes 53 seconds (files took 2.48 seconds to load)
1414 examples, 0 failures, 1 pending
FPROF=1
❯ FPROF=1 bin/rspec spec/lib/gitlab/search_results_spec.rb spec/services/search/global_service_spec.rb spec/services/search/group_service_spec.rb ee/spec/services/search/project_service_spec.rb ee/spec/services/search/global_service_spec.rb ee/spec/lib/gitlab/elastic/search_results_spec.rb ee/spec/services/search/group_service_spec.rb
Running via Spring preloader in process 557057
[TEST PROF INFO] Activating EVENT_PROF with `Spring.after_fork`
[TEST PROF INFO] Activating FPROF with `Spring.after_fork`
[TEST PROF INFO] FactoryProf enabled (simple mode)
WARNING: `around(:context)` hooks are not supported and behave like `around(:example). Called from /home/dgruzd/projects/gdk-ee/gitlab/spec/support/omniauth_strategy.rb:36:in `block in <main>'.
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}
[TEST PROF INFO] EventProf enabled (factory.create)
...........................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................................*..........................................................................................................................................................................................................................................................................................................................................................................................................................................................[TEST PROF INFO] EventProf results for factory.create

Total time: 06:01.809 of 25:30.500 (23.64%)
Total events: 5566

Top 5 slowest suites (by time):

Search::ProjectService (./ee/spec/services/search/project_service_spec.rb:5) – 01:41.131 (1485 / 355) of 06:47.053 (24.84%)
Search::GroupService (./ee/spec/services/search/group_service_spec.rb:5) – 01:38.818 (1555 / 370) of 06:51.920 (23.99%)
Gitlab::Elastic::SearchResults (./ee/spec/lib/gitlab/elastic/search_results_spec.rb:5) – 01:11.410 (873 / 165) of 03:35.945 (33.07%)
Search::GlobalService (./ee/spec/services/search/global_service_spec.rb:5) – 01:08.937 (1272 / 439) of 07:48.726 (14.71%)
Gitlab::SearchResults (./spec/lib/gitlab/search_results_spec.rb:5) – 00:09.021 (176 / 62) of 00:13.419 (67.23%)



Pending: (Failures listed here are expected and do not affect your suite's status)

  1) Gitlab::Elastic::SearchResults blobs Searches CamelCased methods find by first two words
     # Temporarily skipped with xit
     # ./ee/spec/lib/gitlab/elastic/search_results_spec.rb:821


Finished in 25 minutes 35 seconds (files took 2.54 seconds to load)
1414 examples, 0 failures, 1 pending

[TEST PROF INFO] Factories usage

 Total: 7770
 Total top-level: 5566
 Total time: 361.9402s
 Total uniq factories: 14

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

    2099        2096      243.0575s            0.1158s           242.6097s            project
    1959        1100       73.0052s            0.0373s            41.5796s               user
    1255           0       45.3265s            0.0361s             0.0000s          namespace
     679         679       23.5227s            0.0346s            23.5227s              issue
     512         512        9.8851s            0.0193s             9.8851s               note
     470         470       30.0936s            0.0640s            30.0936s      merge_request
     431         431        8.0301s            0.0186s             8.0301s          milestone
     168         168        4.1598s            0.0248s             4.1598s     note_on_commit
      83          79        1.6763s            0.0202s             1.6047s              group
      83           0        0.2368s            0.0029s             0.0000s namespace_settings
      10          10        0.1752s            0.0175s             0.1752s      note_on_issue
       7           7        0.0347s            0.0050s             0.0347s            license
       7           7        0.2193s            0.0313s             0.2193s              admin
       7           7        0.0256s            0.0037s             0.0256s             commit

After

EVENT_PROF="factory.create" bin/rspec spec/lib/gitlab/search_results_spec.rb spec/services/search/global_service_spec.rb spec/services/search/group_service_spec.rb ee/spec/services/search/project_service_spec.rb ee/spec/services/search/global_service_spec.rb ee/spec/lib/gitlab/elastic/search_results_spec.rb ee/spec/services/search/group_service_spec.rb

...

[TEST PROF INFO] EventProf results for factory.create

Total time: 05:58.470 of 25:29.430 (23.44%)
Total events: 5542

Finished in 25 minutes 34 seconds (files took 2.89 seconds to load)
1414 examples, 0 failures, 1 pending

Screenshots (strongly suggested)

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

Related to #321017 (closed)

Edited by Dmitry Gruzd

Merge request reports