Skip to content

fix(sqlalchemy-spanner): isolate test database names and extend stale cleanup cutoff - #18160

Draft
chalmerlowe wants to merge 8 commits into
mainfrom
fix/sqlalchemy-spanner-db-isolation
Draft

fix(sqlalchemy-spanner): isolate test database names and extend stale cleanup cutoff#18160
chalmerlowe wants to merge 8 commits into
mainfrom
fix/sqlalchemy-spanner-db-isolation

Conversation

@chalmerlowe

Copy link
Copy Markdown
Contributor

Problem

When running comprehensive compliance and system test suites for sqlalchemy-spanner, test sessions occasionally encountered "404 Database not found" errors. This happened because:

  1. The stale database cleanup script used a 10-minute timeout threshold, which was too aggressive for longer compliance test runs that exceed 10 minutes.
  2. Concurrent test runs shared a time-based naming pattern without sufficient uniqueness, leading to potential race conditions where one test run's cleanup deleted another active test run's database.

Solution

  1. Updated create_test_database.py to generate session-isolated database names using a truncated timestamp and a random hex suffix (within Spanner's 30-character name limit).
  2. Increased the stale database cleanup cutoff threshold to 30 minutes to accommodate long-running test suites safely without risking quota exhaustion.
  3. Added active duration logging during teardown in drop_test_database.py to report how long each test database was active.

Notes for Reviewers

  • This change prevents premature database dropping during concurrent test execution and provides clear test lifecycle metrics in Nox logs.

@chalmerlowe chalmerlowe self-assigned this Aug 19, 2026

@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 updates the test database lifecycle management for sqlalchemy-spanner. It extends the stale database cleanup threshold from 10 to 30 minutes, introduces session-isolated database IDs, and records database session metadata to track and report active duration upon teardown. The review comments point out critical issues: truncating the Unix timestamp to 9 digits changes the year to 1992, which would cause immediate deletion of newly created databases; the cleanup routine needs to handle both 10-digit and 13-digit timestamps; and the loaded JSON metadata should be type-validated as a dictionary before lookup to comply with the repository's style guide.

Comment thread packages/sqlalchemy-spanner/create_test_database.py
Comment thread packages/sqlalchemy-spanner/create_test_database.py Outdated
Comment thread packages/sqlalchemy-spanner/drop_test_database.py Outdated
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