Skip to content

Improve slow test for lib/sidebars/projects/menus/merge_requests_menu.rb

David Dieulivol requested to merge 413648-improve_test_speed into master

Context

Closes #413648 (closed).

The spec ./spec/lib/sidebars/projects/menus/merge_requests_menu_spec.rb:76 takes 3 minutes to run in the CI (source):

Screenshot_2023-05-31_at_16.25.10

What does this MR do and why?

Make a slow spec much faster (from 1min40sec to 9sec locally 🚀) by stubbing a count instead of creating 1002 MRs in the database to test that we will correctly format the MR count.

Results

Before

 $ be rspec spec/lib/sidebars/projects/menus/merge_requests_menu_spec.rb:75
Run options: include {:focus=>true, :locations=>{"./spec/lib/sidebars/projects/menus/merge_requests_menu_spec.rb"=>[75]}}

Test environment set up in 5.624774 seconds
.

Finished in 1 minute 40.05 seconds (files took 11.44 seconds to load)
1 example, 0 failures

After

 $ be rspec spec/lib/sidebars/projects/menus/merge_requests_menu_spec.rb:75
Run options: include {:focus=>true, :locations=>{"./spec/lib/sidebars/projects/menus/merge_requests_menu_spec.rb"=>[75]}}

Test environment set up in 5.828089 seconds
.

Finished in 8.76 seconds (files took 12.11 seconds to load)
1 example, 0 failures

MR acceptance checklist

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

Merge request reports