Reduce example count in Geo registries update mutation spec
What does this MR do and why?
Mutations::Geo::Registries::Update is tested through with geo registries shared context,
which parameterizes the whole spec over the 43 Geo registry types (Geo::AbuseReportUploadRegistry,
Geo::UploadRegistry, ... Geo::VulnerabilityRemediationUploadRegistry). Two groups of examples
in that loop don't depend on which registry type is under test:
- The class-level authorization check —
specify { expect(described_class).to require_graphql_authorizations(:read_geo_registry) }. This asserts something aboutdescribed_classitself, not about any per-row registry. - The "licensed feature not available" example. Every registry model under
ee/app/models/geo/*_registry.rb(all 43, verified by grep) includesGeo::ReplicableRegistry, whosedeclarative_policy_classalways resolves to'Geo::RegistryPolicy'(ee/app/models/concerns/geo/replicable_registry.rb:43-45). That policy's only rule isrule { can_read_all_geo }.enable :read_geo_registry(ee/app/policies/geo/registry_policy.rb), which depends solely on the current user'scan?(:read_all_geo, :global)— never on the registry class or instance. - The granular-token authorization examples. The mutation declares
authorize_granular_token permissions: :update_geo_registry, boundary: :instance, ...(ee/app/graphql/mutations/geo/registries/update.rb:12-13). The:instanceboundary means the check is instance-wide and never inspects theregistry_idargument, so it can't vary by registry type either.
I hoisted these into one context 'with a single representative registry type', using
:geo_upload_registry as the representative factory, outside the with_them loop. The
resync/reverify/maintenance-mode examples stayed inside the loop, since Geo::RegistryUpdateService
does dispatch differently per registry class and that coverage is real.
No coverage was removed: authorization is still exercised (once, instead of 43 times), and the per-registry resync/reverify/maintenance-mode behavior is still exercised once per registry type, exactly as before.
Spec Run Time Optimization Results
Before optimization:
- 559 examples
- Run time: 2m 34.4s
After optimization:
- 265 examples
- Run time: 1m 28.8s
Improvement:
- Example count reduced by: 52.6% (559 to 265)
- Run time reduced by: 1m 5.6s (65.6s)
Verified with:
bundle exec rspec ee/spec/requests/api/graphql/mutations/geo/registries/update_spec.rb --dry-run # example count
bundle exec rspec ee/spec/requests/api/graphql/mutations/geo/registries/update_spec.rb # full runBoth runs measured in the same local checkout for a fair comparison (same warm Rails boot,
same DB/Gitaly state), swapping only this file's content between the pre- and
post-optimization version. 0 failures on both; pending count went from 43 to 1 (the
now-single representative case for denies access under when namespace enforces granular tokens, an unrelated pre-existing pending state — # namespace has no top-level group).
bundle exec rubocop ee/spec/requests/api/graphql/mutations/geo/registries/update_spec.rb
reports no offenses.
Estimated CI Cost Savings
Using the same methodology as !248403 (merged):
65.6s saved per pipeline × $0.03/minute (large runners: 3x cost factor on $10/1,000 base minutes).
| Scenario | Pipelines/month | Time saved/month | Savings/year |
|---|---|---|---|
| Pessimistic | 15,000 | 273.3h | $5,904.00 |
| Moderate | 30,000 | 546.7h | $11,808.00 |
| Optimistic | 50,000 | 911.1h | $19,680.00 |
How to set up and validate locally
- Checkout this branch.
- Run
bundle exec rspec ee/spec/requests/api/graphql/mutations/geo/registries/update_spec.rb. - Confirm 265 examples, 0 failures.
MR acceptance checklist
Evaluate this MR against the MR acceptance checklist.