Speed up admin feature specs
What does this MR do and why?
This change adds a new use_mock_admin_mode
in
gitlab_enable_admin_mode_sign_in
which allows tests to
enable admin mode faster by mocking the admin mode settings instead of
using capybara and the browser.
use_mock_admin_mode
is enabled by default, so specs that use
gitlab_enable_admin_mode_sign_in
start using the faster version by
default.
Why does this work?
gitlab_enable_admin_mode_sign_in
is frequently used in our specs to simulate a user entering admin mode. It works by visiting new admin session page, and filling out the user password using Capybara.
This is inefficient for most of our tests for the admin section because we must run this code repeatedly in the before
block, for each test. This MR mocks the Gitlab::Auth::CurrentUserMode
setting so the mock user can bypass this check and go directly to admin mode.
It uses enable_admin_mode!
which has been used for admin controllers tests.
Screenshots or screen recordings
Taking admin_runners_spec.rb
as an example, we see a significant decrease in time taken (in my local machine).
Spec | Before | After |
---|---|---|
spec/features/admin/admin_runners_spec.rb |
Finished in 6 minutes 36 seconds (files took 12.14 seconds to load)
|
Finished in 4 minutes 9.7 seconds (files took 12.18 seconds to load)
|
How to set up and validate locally
A green pipeline.
$ bundle exec rspec spec/features/admin
$ bundle exec rspec ee/spec/features/admin
MR acceptance checklist
This checklist encourages us to confirm any changes have been analyzed to reduce risks in quality, performance, reliability, security, and maintainability.
-
I have evaluated the MR acceptance checklist for this MR.