Skip to content

Resolve Slow test in ee/spec/finders/autocomplete/vulnerabilities_autocomplete_finder_spec.rb`

What does this MR do and why?

This spec was flagged as a slow spec.

I improved some of the performance by reducing the number of test records created and consolidating some specs

Performance Summary

These are just taken from me running the specs locally. They will perform differently in CI, however this give the relative performance improvement

Before

Finished in 20.53 seconds (files took 12.81 seconds to load)
18 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:15.328 (69.11% of total time)
Full Output
[TEST PROF INFO] RSpecDissect enabled
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Test environment set up in 1.00624571 seconds

Autocomplete::VulnerabilitiesAutocompleteFinder
  #execute
    when vulnerable is project
      behaves like autocomplete vulnerabilities finder
        when the given user is nil
          is expected to be empty
        when the given user is not nil
          when user does not have access to project
            is expected to be empty
          when user has access to project
            when security dashboards are not enabled
              is expected to be empty
            when security dashboards are enabled
              is expected to contain exactly #<Vulnerability id:1222 [vulnerability:group1/project-1/1222]>
              when multiple vulnerabilities are found
                returns max 5 items
                is sorted descending by id
              when search is provided in params
                and it matches ID of vulnerability
                  is expected to contain exactly #<Vulnerability id:1222 [vulnerability:group1/project-1/1222]>
                and it matches title of vulnerability
                  is expected to contain exactly #<Vulnerability id:1222 [vulnerability:group1/project-1/1222]>
                and it does not match neither title or id of vulnerability
                  is expected to be empty
    when vulnerable is group
      behaves like autocomplete vulnerabilities finder
        when the given user is nil
          is expected to be empty
        when the given user is not nil
          when user does not have access to project
            is expected to be empty
          when user has access to project
            when security dashboards are not enabled
              is expected to be empty
            when security dashboards are enabled
              is expected to contain exactly #<Vulnerability id:1222 [vulnerability:group1/project-1/1222]>
              when multiple vulnerabilities are found
                returns max 5 items
                is sorted descending by id
              when search is provided in params
                and it matches ID of vulnerability
                  is expected to contain exactly #<Vulnerability id:1222 [vulnerability:group1/project-1/1222]>
                and it matches title of vulnerability
                  is expected to contain exactly #<Vulnerability id:1222 [vulnerability:group1/project-1/1222]>
                and it does not match neither title or id of vulnerability
                  is expected to be empty
[TEST PROF INFO] RSpecDissect report

Total time: 00:15.879

Total `let` time: 00:00.082
Total `before(:each)` time: 00:15.735

Top 5 slowest suites (by `let` time):

Autocomplete:...completeFinder (./ee/spec/finders/autocomplete/vulnerabilities_autocomplete_finder_spec.rb:5) – 00:00.082 of 00:15.879 (18)
 ↳ subject – 18
 ↳ vulnerable – 14
 ↳ user – 14

Top 5 slowest suites (by `before(:each)` time):

Autocomplete:...completeFinder (./ee/spec/finders/autocomplete/vulnerabilities_autocomplete_finder_spec.rb:5) – 00:15.735 of 00:15.879 (18)


Finished in 20.53 seconds (files took 12.81 seconds to load)
18 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:15.328 (69.11% of total time)

After

Finished in 7.87 seconds (files took 12.62 seconds to load)
20 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:02.600 (27.85% of total time)
Full Output
[TEST PROF INFO] RSpecDissect enabled
Run options: include {:focus=>true}

All examples were filtered out; ignoring {:focus=>true}

Test environment set up in 0.973400811 seconds

Autocomplete::VulnerabilitiesAutocompleteFinder
  #execute
    when security dashboards are enabled
      when vulnerable is project
        behaves like handles nil or unauthorized user
          when user does not have access to project
            is expected to be empty
          when the given user is nil
            is expected to be empty
        behaves like feature enabled autocomplete vulnerabilities finder
          is expected to contain exactly #<Vulnerability id:1180 [vulnerability:group1/project-1/1180]>, #<Vulnerability id:1179 [vulnerability:group1/project-1/1179]>, #<Vulnerability id:1178 [vulnerability:group1/project-1/1178]>, #<Vulnerability id:1177 [vulnerability:group1/project-1/1177]>, and #<Vulnerability id:1176 [vulnerability:group1/project-1/1176]>
          is expected to be sorted :id and :desc
          when search is provided in params
            and it matches ID of vulnerability
              is expected to contain exactly #<Vulnerability id:1175 [vulnerability:group1/project-1/1175]>
            and it matches title of vulnerability
              is expected to contain exactly #<Vulnerability id:1175 [vulnerability:group1/project-1/1175]>
            and it does not match neither title or id of vulnerability
              is expected to be empty
      when vulnerable is group
        behaves like handles nil or unauthorized user
          when user does not have access to project
            is expected to be empty
          when the given user is nil
            is expected to be empty
        behaves like feature enabled autocomplete vulnerabilities finder
          is expected to contain exactly #<Vulnerability id:1180 [vulnerability:group1/project-1/1180]>, #<Vulnerability id:1179 [vulnerability:group1/project-1/1179]>, #<Vulnerability id:1178 [vulnerability:group1/project-1/1178]>, #<Vulnerability id:1177 [vulnerability:group1/project-1/1177]>, and #<Vulnerability id:1176 [vulnerability:group1/project-1/1176]>
          is expected to be sorted :id and :desc
          when search is provided in params
            and it matches ID of vulnerability
              is expected to contain exactly #<Vulnerability id:1175 [vulnerability:group1/project-1/1175]>
            and it matches title of vulnerability
              is expected to contain exactly #<Vulnerability id:1175 [vulnerability:group1/project-1/1175]>
            and it does not match neither title or id of vulnerability
              is expected to be empty
    when security dashboards are NOT enabled
      when vulnerable is project
        behaves like handles nil or unauthorized user
          when user does not have access to project
            is expected to be empty
          when the given user is nil
            is expected to be empty
        behaves like feature disabled autocomplete vulnerabilities finder
          is expected to be empty
      when vulnerable is group
        behaves like handles nil or unauthorized user
          when user does not have access to project
            is expected to be empty
          when the given user is nil
            is expected to be empty
        behaves like feature disabled autocomplete vulnerabilities finder
          is expected to be empty
[TEST PROF INFO] RSpecDissect report

Total time: 00:01.739

Total `let` time: 00:00.073
Total `before(:each)` time: 00:01.578

Top 5 slowest suites (by `let` time):

Autocomplete:...completeFinder (./ee/spec/finders/autocomplete/vulnerabilities_autocomplete_finder_spec.rb:5) – 00:00.073 of 00:01.739 (20)
 ↳ subject – 20
 ↳ vulnerable – 12
 ↳ user – 12

Top 5 slowest suites (by `before(:each)` time):

Autocomplete:...completeFinder (./ee/spec/finders/autocomplete/vulnerabilities_autocomplete_finder_spec.rb:5) – 00:01.578 of 00:01.739 (20)


Finished in 7.87 seconds (files took 12.62 seconds to load)
20 examples, 0 failures

[TEST PROF INFO] Time spent in factories: 00:02.600 (27.85% of total time)

MR acceptance checklist

Please evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.

Screenshots or screen recordings

Before After
image image

Related to #429615 (closed)

Edited by Michael Becker

Merge request reports