Skip to content

fix(tests/spanner): implement resource cleanup for graphs and tables#2904

Open
NirajNandre wants to merge 5 commits intogoogleapis:mainfrom
NirajNandre:fix/spanner-resource-cleanup
Open

fix(tests/spanner): implement resource cleanup for graphs and tables#2904
NirajNandre wants to merge 5 commits intogoogleapis:mainfrom
NirajNandre:fix/spanner-resource-cleanup

Conversation

@NirajNandre
Copy link
Copy Markdown
Contributor

Description

This PR introduces a robust cleanup mechanism for Spanner integration tests to address resource leakage and the 16-graph bottleneck issue.

  • Fixed the 16-Graph Bottleneck: By querying INFORMATION_SCHEMA.PROPERTY_GRAPHS and dropping them during cleanup, you ensure the database never hits the Spanner limit of 16 graphs.
  • Ordered Deletion: Graphs are dropped before their underlying tables. This prevents foreign key or dependency errors that typically break standard DROP TABLE attempts.
  • Single Batch DDL: Spanner DDL operations are slow. Batching all DROP statements into one UpdateDatabaseDdl call significantly speeds up the cleanup and reduces CI timeouts.
  • Visibility: The DEBUG log statements allow you to verify in the Cloud Build console exactly which resources were identified and whether the deletion succeeded.

Should include a concise description of the changes (bug or feature), it's
impact, along with a summary of the solution

PR Checklist

Thank you for opening a Pull Request! Before submitting your PR, there are a
few things you can do to make sure it goes smoothly:

  • Make sure you reviewed
    CONTRIBUTING.md
  • Make sure to open an issue as a
    bug/issue
    before writing your code! That way we can discuss the change, evaluate
    designs, and agree on the general idea
  • Ensure the tests and linter pass
  • Code coverage does not decrease (if any source code was changed)
  • Appropriate docs were updated (if necessary)
  • Make sure to add ! if this involve a breaking change

🛠️ Fixes #<issue_number_goes_here>

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a 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 introduces a centralized Spanner resource cleanup mechanism for integration tests. It adds a CleanupSpannerResources utility in tests/common.go and refactors TestSpannerToolEndpoints to use t.Cleanup with a unique identifier for resource isolation. The review feedback suggests ensuring the correct drop order for interleaved tables by sorting the schema query, implementing timeouts for cleanup contexts to prevent potential hangs, and using IF EXISTS in DDL statements to ensure idempotency.

@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756 anubhav756 force-pushed the fix/spanner-resource-cleanup branch from d7244d6 to 3744435 Compare March 30, 2026 22:20
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@NirajNandre NirajNandre force-pushed the fix/spanner-resource-cleanup branch from 3744435 to 75e928a Compare March 31, 2026 06:26
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

2 similar comments
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@NirajNandre NirajNandre force-pushed the fix/spanner-resource-cleanup branch 2 times, most recently from 38420ef to 8cb5311 Compare March 31, 2026 08:32
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@NirajNandre NirajNandre force-pushed the fix/spanner-resource-cleanup branch from c21480c to e9b8bc8 Compare March 31, 2026 10:45
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

@anubhav756 anubhav756 force-pushed the fix/spanner-resource-cleanup branch from 6fb52e9 to 1c5becf Compare March 31, 2026 12:11
@NirajNandre NirajNandre force-pushed the fix/spanner-resource-cleanup branch from 1c5becf to c8f57ab Compare March 31, 2026 12:11
@anubhav756 anubhav756 force-pushed the fix/spanner-resource-cleanup branch from c8f57ab to d83886b Compare March 31, 2026 12:12
@anubhav756 anubhav756 marked this pull request as ready for review March 31, 2026 12:22
@anubhav756 anubhav756 requested review from a team as code owners March 31, 2026 12:22
@anubhav756
Copy link
Copy Markdown
Contributor

/gcbrun

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.

3 participants