Speed up EE read-only middleware maintenance mode spec
What does this MR do and why?
Speeds up ee/spec/lib/ee/gitlab/middleware/read_only_spec.rb. It took 181-259 seconds per run in scheduled master pipelines, while the CE version, spec/lib/gitlab/middleware/read_only_spec.rb, takes about 2.5 seconds.
The sign in/out and OAuth are allowed shared example in maintenance_mode_gitlab_ee_instance_shared_examples.rb reloaded routes twice for every example:
- in its
beforehook, withRails.application.reload_routes! - after every example, because
stub_omniauth_saml_configtags the example sospec/support/omniauth.rbreloads routes to clean up
That shared example is included twice and produces 24 examples each time. In the CI job log, each context with two examples took about 9 seconds.
The middleware only needs the LDAP and SAML callback routes to exist, because it matches them with Rails.application.routes.recognize_path. Those routes don't depend on relative_url_root. This MR:
- Draws the routes once per example group with
before_all: it reloads routes with LDAP enabled, then adds the SAML route withprepare_provider_route('saml'). - Restores the original routes afterwards with
restore_provider_routes. - Lets
prepare_provider_routeinspec/support/helpers/login_helpers.rbrun outside an example. With no current example, it skips tagging the example for automatic cleanup, and the caller restores routes itself.
Timings and checks
CI runtime of ee/spec/lib/ee/gitlab/middleware/read_only_spec.rb, from the [RSpecRunTime] lines in the rspec-ee unit pg17 job logs:
| Pipeline | Job | Run time | |
|---|---|---|---|
Before (master) |
https://gitlab.com/gitlab-org/gitlab/-/pipelines/3024629161 | https://gitlab.com/gitlab-org/gitlab/-/jobs/17717433801 | 223.4 s |
Before (master) |
https://gitlab.com/gitlab-org/gitlab/-/pipelines/3024270805 | https://gitlab.com/gitlab-org/gitlab/-/jobs/17714506658 | 181.0 s |
Before (master) |
https://gitlab.com/gitlab-org/gitlab/-/pipelines/3022202627 | https://gitlab.com/gitlab-org/gitlab/-/jobs/17696942758 | 259.0 s |
| After (this MR) | https://gitlab.com/gitlab-org/gitlab/-/pipelines/3027324747 | https://gitlab.com/gitlab-org/gitlab/-/jobs/17737056362 | 19.6 s |
That's about 90% faster, or 160-240 seconds saved per full run. The timing data used to split tests across jobs expected 4m 19s for this file in the same job.
Both specs that use prepare_provider_route inside examples also passed in that pipeline:
spec/controllers/omniauth_callbacks_controller_spec.rbin https://gitlab.com/gitlab-org/gitlab/-/jobs/17737056255ee/spec/controllers/ee/omniauth_callbacks_controller_spec.rbin https://gitlab.com/gitlab-org/gitlab/-/jobs/17737056371
Checks:
- Without the route setup, the 16 LDAP and SAML callback examples fail. So the examples still depend on the routes being drawn.
- The CE middleware spec still passes alongside the EE one (159 examples).
- Running
ee/spec/lib/ee/gitlab/middleware/read_only_spec.rb, thenee/spec/routing/user_routing_spec.rbandspec/routing/routing_spec.rb, in that order, passes. So the routes are restored for later specs.
References
- Tracking issue: #638347 (closed)
- Found by ranking specs in https://gitlab-org.gitlab.io/gitlab/knapsack/report-master.json by runtime.
Screenshots or screen recordings
Not applicable: test-only change.
How to set up and validate locally
Not applicable: test-only change with no manual steps.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist. It helps you analyze changes to reduce risks in quality, performance, reliability, security, and maintainability.