Resolve "Skip setup of gitlab-shell, gitaly, ... for specs that don't need it."
EE MR: https://gitlab.com/gitlab-org/gitlab-ee/merge_requests/5180
What does this MR do?
This introduce a new spec/fast_spec_helper.rb
file that doesn't load the whole Rails env, and also skips the setup of gitlab-shell, gitaly etc.
This results in blazing-fast test runs:
Timing to run spec/lib/gitlab_spec.rb
:
bundle exec rspec |
bin/rspec (Spring) |
|
---|---|---|
require 'spec_helper' |
31.244s | 5.223s |
require 'fast_spec_helper' |
1.159s | 1.141s |
Following are the detailed runs:
bundle exec rspec
and require 'spec_helper'
With › time bundle exec rspec spec/lib/gitlab_spec.rb
==> Setting up GitLab Shell...
GitLab Shell setup in 0.61857 seconds...
==> Setting up Gitaly...
Gitaly setup in 1.222089 seconds...
...
Finished in 2.79 seconds (files took 27.38 seconds to load)
3 examples, 0 failures
bundle exec rspec spec/lib/gitlab_spec.rb 17.35s user 9.40s system 85% cpu 31.244 total
bin/rspec
(Spring) and require 'spec_helper'
With › time bin/rspec spec/lib/gitlab_spec.rb
Running via Spring preloader in process 40180
==> Setting up GitLab Shell...
GitLab Shell setup in 0.627667 seconds...
==> Setting up Gitaly...
Gitaly setup in 0.921427 seconds...
...
Finished in 2.43 seconds (files took 1.82 seconds to load)
3 examples, 0 failures
bin/rspec spec/lib/gitlab_spec.rb 0.24s user 0.10s system 6% cpu 5.223 total
bundle exec rspec
and require 'fast_spec_helper'
With › time bundle exec rspec spec/lib/gitlab_spec.rb
...
Finished in 0.01363 seconds (files took 0.42084 seconds to load)
3 examples, 0 failures
bundle exec rspec spec/lib/gitlab_spec.rb 0.79s user 0.30s system 93% cpu 1.159 total
bin/rspec
(Spring) and require 'fast_spec_helper'
With › time bin/rspec spec/lib/gitlab_spec.rb
Running via Spring preloader in process 40289
...
Finished in 0.0129 seconds (files took 0.07418 seconds to load)
3 examples, 0 failures
bin/rspec spec/lib/gitlab_spec.rb 0.23s user 0.08s system 27% cpu 1.141 total
Are there points in the code the reviewer needs to double check?
Using the new fast_spec_helper
, we'll have to add some require_dependency
and tweak our code a bit since we don't benefit from Rails autoloading nor Bundler's gems load of all the gems in the :default
group.
Why was this MR needed?
Because sometimes you just want to run a unit test that doesn't rely on Rails, and there's no reason this should load all Rails and its dependencies for your test to run.
Does this MR meet the acceptance criteria?
-
Documentation created/updated - Review
-
Has been reviewed by Backend
-
-
Conform by the style guides -
Squashed related commits together -
End-to-end tests pass ( package-and-qa
manual pipeline job)
What are the relevant issue numbers?
Closes #44713 (closed)
Edited by Rémy Coutable