GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — chore(bigtable): prevent test leaks by daniel-sanche · Pull Request #17350 · googleapis/google-cloud-python Conversation
|
| 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 |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
/gemini review |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
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.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
There was an error while loading. Please reload this page.
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>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.