Repository navigation
Conversation
…eardown Label instances created in test_instance_api.py with the standard python-spanner-systests and created labels so cleanup_old_instances sweeps them if a run crashes. Use scrub_instance_ignore_not_found in shared_instance teardown with try/finally around creation wait, and add matching async stale-instance cleanup and scrubbing in _async/conftest.py.
There was a problem hiding this comment.
Code Review
This pull request improves the cleanup and management of stale Spanner instances and databases in system tests, introducing asynchronous cleanup helpers (_scrub_instance_ignore_not_found and _cleanup_old_instances) and ensuring standard labels are applied to newly created instances. However, a critical issue was identified in the asynchronous test configuration where the synchronous factory method to_scrub.database() is incorrectly awaited, which will raise a TypeError at runtime and cause the cleanup process to fail.
| """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 to_scrub.database() method is a synchronous factory method that returns an AsyncDatabase instance without performing any network I/O. Awaiting it will raise a TypeError at runtime, which will propagate and cause the teardown/cleanup helper to fail.
| 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.
The async Instance.database() method is an async def coroutine (it awaits db._pool.bind(db) in spanner_v1/_async/instance.py), so awaiting it here is required, same as shared_instance.database() below in this file.
| 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.
The to_scrub.database() method is a synchronous factory method that returns an AsyncDatabase instance without performing any network I/O. Awaiting it will raise a TypeError at runtime, which will propagate and cause the teardown/cleanup helper to fail.
| db = await to_scrub.database(db_name.split("/")[-1]) | |
| db = to_scrub.database(db_name.split("/")[-1]) |
There was a problem hiding this comment.
Same as above: the async Instance.database() method is an async def coroutine in spanner_v1/_async/instance.py (it awaits db._pool.bind(db)), so dropping await here would leave db as an unawaited coroutine.
|
Splitting into 3 smaller independent PRs for easier review |
Context & Problem
Spanner system tests can leak instances when instance-creation tests crash without standard sweeper labels, when shared_instance teardown fails on remaining backups or drop-protected databases, or when the async suite leaves stale instances behind.
Summary of Changes
Why This Approach
Reuses the existing label-based 3-hour sweeper convention across both sync and async suites while fixing real teardown races (NotFound, drop protection ordering, and db.drop) without changing production client code.
Diff size note: Changes are confined to system test helpers and fixtures across sync and async suites (121 insertions across 4 test files) to fix all identified teardown and sweeper gaps together.
Intentionally Out of Scope
Verification
ruff check (including import sorting), ruff format --check, py_compile, behavioral verification of sync/async scrubbers, and two independent Owl review passes