Repository navigation
Conversation
The Spanner async system test suite creates labeled instances when GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE is set, but never sweeps stale instances on startup and calls raw instance.delete() without scrubbing backups or drop-protected databases or guarding creation waits.
There was a problem hiding this comment.
Code Review
This pull request introduces automated cleanup of stale system-test instances and backups in the asynchronous test configuration. It adds helper functions to sweep old instances and safely scrub databases, drop protection, and backups, integrating these into the shared_instance fixture lifecycle. However, there are critical runtime issues where the synchronous factory method Instance.database is incorrectly awaited on lines 31 and 48, which will raise a TypeError and should be corrected.
| """Delete backups, disable DB drop protection, and delete an async instance.""" | ||
| try: | ||
| async for database_pb in await to_scrub.list_databases(): | ||
| db = await to_scrub.database(database_pb.name.split("/")[-1]) |
There was a problem hiding this comment.
The Instance.database method is a synchronous factory method that returns a Database object. Awaiting it will raise a TypeError at runtime because the returned object is not awaitable. Remove the await keyword.
| db = await to_scrub.database(database_pb.name.split("/")[-1]) | |
| db = to_scrub.database(database_pb.name.split("/")[-1]) |
There was a problem hiding this comment.
to_scrub is an async Instance (google.cloud.spanner_v1._async.instance.Instance), where database() is an async def that awaits db._pool.bind(db). Removing await here would return an unawaited coroutine and break db.reload().
| try: | ||
| async for backup_pb in await to_scrub.list_backups(): | ||
| for db_name in backup_pb.referencing_databases: | ||
| db = await to_scrub.database(db_name.split("/")[-1]) |
There was a problem hiding this comment.
Same as above: to_scrub is an async Instance (google.cloud.spanner_v1._async.instance.Instance), where database() is async def because it awaits db._pool.bind(db). Keeping await here to match the rest of tests/system/_async/.
|
Closing speculative hardening PR without live leaked-resource evidence |
Context & Problem
The Spanner async system test suite creates labeled instances when GOOGLE_CLOUD_TESTS_CREATE_SPANNER_INSTANCE is set, but never sweeps stale instances on startup and calls raw instance.delete() without scrubbing backups or drop-protected databases or guarding creation waits.
Summary of Changes
Why This Approach
Brings async system test cleanup to parity with sync tests using native async APIs and keeping sync/async boundaries clean.
Intentionally Out of Scope
Verification
nox -s lint mypy-3.14 unit-3.14 unit-3.10 cover and two independent Owl review passes