fix(tests/postgres): implement uuid-based isolation and reliable resource cleanup (#2377)

…atements

## Description

This PR resolves integration test resource leaks and memory exhaustion
by implementing per-test isolation and reliable teardown logic.

**Files Updated:**

- **tests/common.go**: Refactored CleanupPostgresTables to target
specific uniqueID resources.
- **tests/alloydbpg/alloydb_pg_integration_test.go**: Integrated
t.Cleanup and unique ID logging.

## 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](https://github.com/googleapis/genai-toolbox/blob/main/CONTRIBUTING.md)
- [ ] Make sure to open an issue as a

[bug/issue](https://github.com/googleapis/genai-toolbox/issues/new/choose)
  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 #<2463>
This commit is contained in:
Niraj Nandre
2026-02-17 19:09:53 +05:30
committed by GitHub
parent d4ff6bebe9
commit 8a96fb1a88
5 changed files with 57 additions and 31 deletions

View File

@@ -114,13 +114,18 @@ func TestCloudSQLPgSimpleToolEndpoints(t *testing.T) {
t.Fatalf("unable to create Cloud SQL connection pool: %s", err)
}
// cleanup test environment
tests.CleanupPostgresTables(t, ctx, pool)
// Generate a unique ID
uniqueID := strings.ReplaceAll(uuid.New().String(), "-", "")
// create table name with UUID
tableNameParam := "param_table_" + strings.ReplaceAll(uuid.New().String(), "-", "")
tableNameAuth := "auth_table_" + strings.ReplaceAll(uuid.New().String(), "-", "")
tableNameTemplateParam := "template_param_table_" + strings.ReplaceAll(uuid.New().String(), "-", "")
// This will execute after all tool tests complete (success, fail, or t.Fatal)
t.Cleanup(func() {
tests.CleanupPostgresTables(t, context.Background(), pool, uniqueID)
})
//Create table names using the UUID
tableNameParam := "param_table_" + uniqueID
tableNameAuth := "auth_table_" + uniqueID
tableNameTemplateParam := "template_param_table_" + uniqueID
// set up data for param tool
createParamTableStmt, insertParamTableStmt, paramToolStmt, idParamToolStmt, nameParamToolStmt, arrayToolStmt, paramTestParams := tests.GetPostgresSQLParamToolInfo(tableNameParam)