Speed up GroupSaml::SsoEnforcer spec
What does this MR do and why?
Speeds up ee/spec/lib/gitlab/auth/group_saml/sso_enforcer_spec.rb. It took 9m 49s for 249 examples in a scheduled master job, or about 2.4 seconds per example for a library unit spec.
The when SAML SSO is enabled for resource table has 236 rows. For every row, let and before created:
- a SAML provider and its group
- a SAML identity
- a subgroup, a shared group and a project
- 6 users and a deploy token
- a group link
- 5 memberships, each of which refreshes project authorizations
This MR creates those records once for the table, with let_it_be_with_refind and before_all.
Rows still change the SAML provider, the resource's visibility, the member's access level and the user's admin and auditor flags. Each example's transaction rolls those changes back, and let_it_be_with_refind loads fresh objects for every example. I used refind rather than reload so that values cached in instance variables (strong_memoize) can't leak between rows.
Timings and checks
Local runs:
| Examples | Run time | Factory time | |
|---|---|---|---|
| Before | 249 | 9m 36s | 2m 38s |
| After | 249 | 1m 4s | 6.6 s |
Checks:
- Passes with random seeds 1234 and 98765, and with
--order reverse. - With
SsoEnforcer#access_restricted?changed to ignore the active SAML session, 14 examples fail with both the old and the new spec.
References
- Tracking issue: #638347 (closed)
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.