Skip to content

fix(bigtable): harden system test instance teardown and sweeper - #19257

Closed
ohmayr wants to merge 1 commit into
mainfrom
fix/bigtable-system-test-cleanup
Closed

ohmayr wants to merge 1 commit into
mainfrom
fix/bigtable-system-test-cleanup

Conversation

@ohmayr

@ohmayr ohmayr commented Nov 29, 2026

Copy link
Copy Markdown
Contributor

Context & Problem

Bigtable system tests can leak instances when v2_client runs leave stale instances unswept, when instance creation waits time out before yield, or when stale instances still hold backups that block delete_instance.

Summary of Changes

  • Delete backups under stale instances before calling delete_instance in tests/system/utils.py (instantiating BigtableTableAdminClient lazily).
  • Wire a session-scoped autouse cleanup_old_instances fixture into tests/system/v2_client/conftest.py and guard admin_instance_populated and data_instance_populated creation waits with try/finally without masking creation errors.
  • Let tests/system/data/init.py use the full default prefix tuple in clear_stale_instances().
  • Add unit tests in tests/unit/test_system_cleanup.py covering backup-before-instance ordering, list_backups failures, and per-backup delete errors.

Why This Approach

Extends the existing clear_stale_instances helper and fixture patterns so all Bigtable system test suites share backup-aware cleanup without modifying production client code.

Diff size note: System test fixture and helper changes are 80 lines; the remaining lines are focused unit tests with 100% coverage in tests/unit/test_system_cleanup.py.

Intentionally Out of Scope

  • Modifying production google-cloud-bigtable client code
  • Refactors to unrelated system test suites or CI workflow configs

Verification

ruff check (including import sorting), ruff format --check, flake8, pytest with 100% coverage on test_system_cleanup.py, and two independent Owl review passes

Delete backups under stale instances before calling delete_instance in
clear_stale_instances so backed-up instances do not fail cleanup. Wire
clear_stale_instances into v2_client/conftest.py, let data system tests
use the full default prefix tuple, and wrap v2_client session fixture
creation waits in try/finally so timed-out instances are still deleted.

@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 automatic cleanup of stale backups before deleting stale Bigtable instances during system tests. It adds a helper function _delete_instance_backups in utils.py to list and delete backups, updates clear_stale_instances to invoke this helper, and adds a session-scoped autouse fixture cleanup_old_instances in conftest.py to automate the cleanup process. Additionally, the fixtures admin_instance_populated and data_instance_populated are refactored to handle teardown exceptions more robustly, and comprehensive unit tests are added in test_system_cleanup.py to verify the new cleanup logic. No review comments were provided, so there is no feedback to address.

@ohmayr

ohmayr commented Nov 29, 2026

Copy link
Copy Markdown
Contributor Author

Splitting into 2 smaller independent PRs for easier review

@ohmayr ohmayr closed this Nov 29, 2026
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