Skip to content

tests: cleanup stale databases in spanner system tests#17668

Merged
parthea merged 1 commit into
mainfrom
feat/spanner-cleanup-stale-dbs
Jul 13, 2026
Merged

tests: cleanup stale databases in spanner system tests#17668
parthea merged 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
@chalmerlowe chalmerlowe self-assigned this Jul 9, 2026
@chalmerlowe chalmerlowe added the automerge Merge the pull request once unit tests and other checks pass. label Jul 13, 2026
@parthea

parthea commented Jul 13, 2026

Copy link
Copy Markdown
Contributor

/gemini review

@parthea parthea changed the title feat: cleanup stale databases in spanner system tests tests: cleanup stale databases in spanner system tests Jul 13, 2026
@parthea parthea enabled auto-merge (squash) July 13, 2026 17:56

@gemini-code-assist gemini-code-assist Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request introduces a cleanup_stale_databases helper function to remove stale databases during system tests, which is integrated into the shared_instance fixture. The review feedback points out that instance.list_databases() already returns Database wrapper objects, making the manual instantiation of db redundant, and suggests a simplified loop structure.

Comment thread packages/google-cloud-spanner/tests/system/_helpers.py
@parthea parthea merged commit 002d650 into main Jul 13, 2026
29 checks passed
@parthea parthea deleted the feat/spanner-cleanup-stale-dbs branch July 13, 2026 18:40
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

automerge Merge the pull request once unit tests and other checks pass.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants