GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — chore(bigtable): prevent test leaks by daniel-sanche · Pull Request #17350 · googleapis/google-cloud-python

Conversation

@daniel-sanche

@daniel-sanche daniel-sanche commented Jun 2, 2026 •
edited
Loading

Uh oh!

There was an error while loading. Please reload this page.

Copy link
Copy Markdown
Contributor

The bigtable system tests were leaving left-over instances, which could cause future tests to fail until they were manually cleaned up

This PR improves the test logic to make sure resources are properly cleaned up

Also added a fixture to remove test instances created more than a day ago

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction
@daniel-sanche
chore(bigtable): prevent test leaks
7143f48
@daniel-sanche
daniel-sanche requested a review from a team as a code owner June 2, 2026 18:48
gemini-code-assist[bot]
gemini-code-assist Bot reviewed Jun 2, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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 Bigtable system tests by changing cleanup fixtures from session to function scope, reversing deletion order, and catching general exceptions during cleanup. It also adds immediate cleanup logic during instance and backup creation. The review feedback correctly identifies a bug where replacing placeholders in the cleanup lists prevents proper removal during a failure, leading to redundant deletion attempts. It recommends simplifying the code by not replacing the placeholders, which also avoids potential race conditions.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_async.py Outdated
Comment on lines +175 to +208
try:
instance = await operation.result()

# replace with full instance object
instances_to_delete[-1] = instance

# Create a table within the instance
create_table_request = admin_v2.CreateTableRequest(
parent=instance_admin_client.instance_path(project_id, instance_id),
table_id=TEST_TABLE_NAME,
table=admin_v2.Table(
column_families={
TEST_COLUMMN_FAMILY_NAME: admin_v2.ColumnFamily(),
}
),
)

instance = await operation.result()
table = await table_admin_client.create_table(create_table_request)

# replace with full instance object
instances_to_delete[-1] = instance
# Populate with dummy data
await populate_table(
table_admin_client, data_client, instance, table, INITIAL_CELL_VALUE
)

# Create a table within the instance
return instance, table
except Exception:
# cleanup immediately on failure
try:
await instance_admin_client.delete_instance(name=instance_name)
except Exception:
pass
if instance_placeholder in instances_to_delete:
instances_to_delete.remove(instance_placeholder)
raise

@gemini-code-assist gemini-code-assist Bot Jun 2, 2026

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

high

If an exception occurs during table creation or population (lines 182-197) after instances_to_delete[-1] = instance has executed, the except Exception block on line 200 will attempt to remove instance_placeholder from instances_to_delete. However, since instance_placeholder was already replaced by instance in the list, instance_placeholder in instances_to_delete will evaluate to False, leaving the already-deleted instance in instances_to_delete. This causes a redundant deletion attempt in the fixture's finally block.

Additionally, using instances_to_delete[-1] to replace the placeholder is risky if any concurrent operations modify the list.

Since the instances_to_delete fixture only requires the .name attribute of the objects in the list to perform deletion, and instance_placeholder already has the correct name, we can avoid replacing the placeholder entirely, which simplifies the code and avoids this bug.

        try:
            instance = await operation.result()

            # Create a table within the instance
            create_table_request = admin_v2.CreateTableRequest(
                parent=instance_admin_client.instance_path(project_id, instance_id),
                table_id=TEST_TABLE_NAME,
                table=admin_v2.Table(
                    column_families={
                        TEST_COLUMMN_FAMILY_NAME: admin_v2.ColumnFamily(),
                    }
                ),
            )

            table = await table_admin_client.create_table(create_table_request)

            # Populate with dummy data
            await populate_table(
                table_admin_client, data_client, instance, table, INITIAL_CELL_VALUE
            )

            return instance, table
        except Exception:
            # cleanup immediately on failure
            try:
                await instance_admin_client.delete_instance(name=instance_name)
            except Exception:
                pass
            if instance_placeholder in instances_to_delete:
                instances_to_delete.remove(instance_placeholder)
            raise

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

@daniel-sanche
daniel-sanche marked this pull request as draft June 2, 2026 19:00
@daniel-sanche
removed duplicate code
0025c54
@daniel-sanche

daniel-sanche commented Jun 2, 2026

Copy link
Copy Markdown
Contributor Author

/gemini review

gemini-code-assist[bot] reacted with eyes emoji
All reactions
  • 👀 1 reaction

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

gemini-code-assist[bot]
gemini-code-assist Bot reviewed Jun 2, 2026
View reviewed changes

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

Copy link
Copy Markdown
Contributor

There was a problem hiding this comment.

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 system tests for Google Cloud Bigtable by changing the scope of cleanup fixtures from session to function, reversing the deletion order of instances and backups, and catching general exceptions instead of only NotFound errors during resource cleanup. The feedback recommends logging or printing the caught exceptions instead of swallowing them silently, and including exception details in the print statements when table or view deletions fail to make debugging resource leaks easier.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

All reactions
Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_async.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/admin_overlay/test_system_autogen.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/data/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/data/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

Comment thread packages/google-cloud-bigtable/tests/system/data/__init__.py Resolved

Uh oh!

There was an error while loading. Please reload this page.

daniel-sanche and others added 6 commits June 2, 2026 13:14
@daniel-sanche @gemini-code-assist
Apply suggestions from code review
6adb279
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@daniel-sanche
fix lint
7bbb685
@daniel-sanche
added logic to clear out old test data
b59dc08
@daniel-sanche
fix lint
ecdaa41
@daniel-sanche
regenerated sync code
c06fbaf
@daniel-sanche
Merge branch 'main' into bigtable_cleanup
55f97b3
@daniel-sanche
daniel-sanche marked this pull request as ready for review June 4, 2026 22:46
@daniel-sanche daniel-sanche mentioned this pull request Jun 4, 2026
google-cloud-bigtable and google-cloud-bigquery test failure #17327
Closed
1 task done
parthea
parthea approved these changes Jun 8, 2026
View reviewed changes
@parthea
parthea merged commit 94c09fd into main Jun 8, 2026
28 checks passed

Uh oh!

There was an error while loading. Please reload this page.

@parthea
parthea deleted the bigtable_cleanup branch June 8, 2026 16:28
This was referenced Aug 18, 2026
test(bigtable): temporarily disable real-service system tests, keep emulated #18148
Merged
chore(bigtable): improve system test instance usage #18149
Merged
daniel-sanche added a commit that referenced this pull request Aug 31, 2026
@daniel-sanche @gemini-code-assist
chore(bigtable): improve system test instance usage (#18149)
f5de310
We have been hitting quota limits on bigtable system tests recently.
This PR attempts to make a few improovements:
- Patched a [bug in the system_emulated
tests](#18148),
where the tests would still try to [clean up stale GCP
instances](#17350),
even in emulator mode
- Also set a new dummy `GOOGLE_CLOUD_PROJECT` envvar in system_emulated
mode, to prevent talking to the live GCP environment
- Improved the stale clean-up logic to add a cap to only clean up at max
5 old instances, along with additional logs
- Identified a couple placed in the tests where we can re-use existing
instances instead of spinning up new ones

---------

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Reviewers

@parthea parthea parthea approved these changes
+1 more reviewer
@gemini-code-assist gemini-code-assist[bot] gemini-code-assist[bot] left review comments
Reviewers whose approvals may not affect merge requirements

Uh oh!

There was an error while loading. Please reload this page.

Assignees

No one assigned

Labels

None yet

Projects

None yet

Milestone

No milestone

Development

Successfully merging this pull request may close these issues.

Uh oh!

There was an error while loading. Please reload this page.

2 participants

@daniel-sanche @parthea
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
You are visitor 01402775 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.