Repository navigation
chore(alloydb-postgres): harden integration test cleanup and add AlloyDB Omni coverage - #4596
Conversation
…yDB Omni coverage - Close both `pgxpool.Pool` and `alloydbconn.Dialer` in `t.Cleanup` before DB teardowns so LIFO closes connections last without leaking connector refreshers, and register `pool.Close` in `cloudsqlpg`, `postgres`, and `alloydbomni`. - Add `RegisterTeardown` (`sync.Once` + `t.Cleanup`) and bounded uncanceled `postgresCleanupContext` across shared Postgres test helpers (`SetupPostgresSQLTable`, `CleanupPostgresTables`, `SetupPostgresVectorTable`, schemas, views, triggers, publications, indexes, sequences, databases, roles, locks, extensions, stats, and stored procedures), using `Exec` instead of unclosed `Query` calls and reporting cleanup errors via `t.Errorf`. - Scope `RunExecuteSqlToolInvokeTest`, `RunPostgresListPublicationTablesTest`, and `RunPostgresListLocksTest` to per-run UUID-suffixed names on shared instances, preserve pre-existing extensions in `createPostgresExtension`, and add a read-write cleanup backstop in `TestAlloyDBPg_ReadOnlyVulnerabilityBlock`. - Add `TestAlloyDBOmniToolEndpoints` container coverage and align the `alloydb-omni` Cloud Build shard trigger and auth env vars.
There was a problem hiding this comment.
Code Review
This pull request significantly improves the reliability and concurrency of Postgres-based integration tests (including AlloyDB Omni, AlloyDB PG, Cloud SQL PG, and standard Postgres). It introduces a centralized RegisterTeardown helper that utilizes t.Cleanup for LIFO execution, implements bounded uncanceled contexts (postgresCleanupContext) to prevent teardown hangs, and adopts per-run unique table names to avoid collisions during concurrent test execution on shared database instances. Additionally, a new test suite TestAlloyDBOmniToolEndpoints has been added to expand test coverage for AlloyDB Omni. I have no further feedback to provide as the changes are well-structured and follow Go testing best practices.
Description
Hardens integration test resource cleanup and shared-instance isolation for AlloyDB for PostgreSQL (
tests/alloydbpg) and shared Postgres test helpers, and adds isolated container-backed tool endpoint coverage against AlloyDB Omni (tests/alloydbomni).Summary of Changes
t.CleanupLIFO): Closes bothpgxpool.Poolandalloydbconn.Dialerintests/alloydbpg(and registerst.Cleanup(pool.Close)/t.Cleanup(containerCleanup)inalloydbomni,cloudsqlpg, andpostgres) before database object teardowns so connections remain open until allDROPstatements finish.RegisterTeardown+postgresCleanupContext): Registers idempotentt.Cleanupcallbacks immediately upon creating tables, schemas, views, triggers, publications, indexes, sequences, roles, databases, extensions, and table locks, using bounded uncanceled contexts (context.WithTimeout(context.WithoutCancel(ctx), 2*time.Minute)),pool.Execinstead of unclosedpool.Query, andt.Errorfinstead oft.Fatalf/t.Logf.RunExecuteSqlToolInvokeTest(WithExecuteSqlTableName),RunPostgresListPublicationTablesTest, andRunPostgresListLocksTest, preserves pre-existing extensions increatePostgresExtension, escapesLIKEwildcards and closesrowsbeforeDROP SCHEMAincleanupOldSchemas, and adds a read-writeDROP TABLE IF EXISTScleanup backstop inTestAlloyDBPg_ReadOnlyVulnerabilityBlock.TestAlloyDBOmniToolEndpointsintests/alloydbomniexercisingpostgres-sql,postgres-execute-sql, template parameters,list_tables, andpgvectorsemantic search, and updates.ci/integration.cloudbuild.yamlto triggeralloydb-omnioninternal/tools/postgres/changes.Security Considerations
pg_triggerlookup with$1, sanitizes dynamic identifiers viapgx.Identifier, and adds a defensive cleanup backstop aroundalloydb_session_read_only=lockedverification without modifying production source/tool auth or SQL execution paths.PR Checklist
!if this involves a breaking change