mirror of
https://github.com/googleapis/genai-toolbox.git
synced 2026-02-18 11:02:26 -05:00
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:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user