Skip to content

feat: cleanup stale databases in spanner system tests#17668

Open
chalmerlowe wants to merge 1 commit into
mainfrom
feat/spanner-cleanup-stale-dbs
Open

feat: cleanup stale databases in spanner system tests#17668
chalmerlowe wants to merge 1 commit into
mainfrom
feat/spanner-cleanup-stale-dbs

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Problem

Spanner system tests can sometimes leave behind test databases if a run is interrupted or fails to clean up properly. Over time, these stale databases can accumulate, potentially hitting quota limits or cluttering the test environment.

Solution

Introduced a proactive cleanup mechanism to remove stale databases during test setup.

  • Added cleanup_stale_databases helper: A new function in _helpers.py that lists databases in a given instance and drops any that are older than a specified cutoff (defaulting to 10 minutes/600 seconds).
  • Drop Protection Handling: The helper explicitly disables enable_drop_protection if it's set, ensuring that even protected test databases can be cleaned up automatically.
  • Fixture Integration: Integrated this cleanup call into the shared_instance fixture in conftest.py, ensuring that every test session starts by cleaning up residue from previous runs.

Impact

  • Reduces the risk of test failures due to database quota exhaustion.
  • Keeps the Spanner instance used for testing clean.
  • Resilient against partial failures by handling NotFound and other API errors during cleanup.

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@chalmerlowe

Copy link
Copy Markdown
Contributor Author

/gemini review

@gemini-code-assist

Copy link
Copy Markdown
Contributor

Warning

Gemini encountered an error creating the review. You can try again by commenting /gemini review.

@chalmerlowe chalmerlowe marked this pull request as ready for review July 8, 2026 19:46
@chalmerlowe chalmerlowe requested a review from a team as a code owner July 8, 2026 19:46
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.

1 participant