Skip to content

Add tests for rotate CLI and request_rotation#76

Closed
gijzelaerr wants to merge 5 commits into
mainfrom
spotify/add-rotate-cli-tests
Closed

Add tests for rotate CLI and request_rotation#76
gijzelaerr wants to merge 5 commits into
mainfrom
spotify/add-rotate-cli-tests

Conversation

@gijzelaerr

Copy link
Copy Markdown
Member

Summary

Adds test coverage for two critical production paths that previously had zero tests:

request_rotation (5 tests)

  • Calls rotate_certificate and sends notification on commit
  • Skips rotation without --commit
  • Skips notification without --message
  • Handles rotation errors gracefully (no crash, emits failure metric)
  • Emits success metric on successful rotation

Bulk rotation rotate -o OLD -n NEW (3 tests)

  • Regression test for list-mutation bug (PR Fix rotate CLI skipping endpoints due to list mutation during iteration #71): verifies all 6 endpoints are rotated, not 5. The bug was caused by iterating old_cert.endpoints (a live SQLAlchemy relationship) while request_rotation mutates it by reassigning endpoint.certificate.
  • Single-endpoint rotation by name
  • Dry-run mode (no --commit) does not call rotate_certificate

Context

The list-mutation bug was discovered during the *.g2.spotify.com Phase 4 migration — 5 of 6 dealer SSL proxies rotated, 1 was silently skipped. The fix (PR #71) wraps the iterator in list(), but without tests the regression could easily return.

Based on old_fork (the known-good commit 7e11440c) since main has a broken boto3 pin.

gijzelaerr and others added 2 commits July 7, 2026 11:00
`old_cert.endpoints` is a live SQLAlchemy relationship. When
`request_rotation` reassigns `endpoint.certificate = new_cert`, the
endpoint is removed from the collection mid-iteration, causing one
endpoint to be skipped per rotation call.

Wrap in `list()` to snapshot the collection before iterating.
Cover the two critical paths that had zero test coverage:

1. request_rotation: verifies it calls rotate_certificate,
   sends notifications, handles errors, and emits metrics.

2. Bulk rotation (rotate -o OLD -n NEW): regression test for
   the list-mutation bug where iterating old_cert.endpoints
   while request_rotation mutates it caused 1 endpoint to be
   skipped per rotation call. Tests that all 6 endpoints are
   rotated, not 5.

Also covers single-endpoint rotation and dry-run mode.
@gijzelaerr gijzelaerr changed the base branch from old_fork to main July 7, 2026 09:54
@gijzelaerr

Copy link
Copy Markdown
Member Author

Superseded by new PR based on main

@gijzelaerr gijzelaerr closed this Jul 7, 2026
@coveralls

Copy link
Copy Markdown

Coverage Report for CI Build 28863768566

Coverage remained the same at 59.879%

Details

  • Coverage remained the same as the base build.
  • Patch coverage: No coverable lines changed in this PR.
  • No coverage regressions found.

Uncovered Changes

No uncovered changes found.

Coverage Regressions

No coverage regressions found.


Coverage Stats

Coverage Status
Relevant Lines: 992
Covered Lines: 594
Line Coverage: 59.88%
Coverage Strength: 0.6 hits per line

💛 - Coveralls

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants