8000 chore(alloydb-postgres): harden integration test cleanup and add AlloyDB Omni coverage by arijitbakshi15-stack · Pull Request #4596 · googleapis/mcp-toolbox · GitHub
[go: up one dir, main page]

Skip to content

chore(alloydb-postgres): harden integration test cleanup and add AlloyDB Omni coverage - #4596

Open
arijitbakshi15-stack wants to merge 1 commit into
googleapis:mainfrom
arijitbakshi15-stack:chore/alloydbpg-integration-test-cleanup
Open

arijitbakshi15-stack wants to merge 1 commit into
googleapis:mainfrom
arijitbakshi15-stack:chore/alloydbpg-integration-test-cleanup

Conversation

@arijitbakshi15-stack
Copy link
Copy Markdown
Contributor

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

  • Pool & Connector Lifecycle (t.Cleanup LIFO): Closes both pgxpool.Pool and alloydbconn.Dialer in tests/alloydbpg (and registers t.Cleanup(pool.Close) / t.Cleanup(containerCleanup) in alloydbomni, cloudsqlpg, and postgres) before database object teardowns so connections remain open until all DROP statements finish.
  • Immediate, Bounded Teardowns (RegisterTeardown + postgresCleanupContext): Registers idempotent t.Cleanup callbacks 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.Exec instead of unclosed pool.Query, and t.Errorf instead of t.Fatalf / t.Logf.
  • Shared-Instance Isolation & Read-Only Backstop: Passes per-run UUID-suffixed table/publication names to RunExecuteSqlToolInvokeTest (WithExecuteSqlTableName), RunPostgresListPublicationTablesTest, and RunPostgresListLocksTest, preserves pre-existing extensions in createPostgresExtension, escapes LIKE wildcards and closes rows before DROP SCHEMA in cleanupOldSchemas, and adds a read-write DROP TABLE IF EXISTS cleanup backstop in TestAlloyDBPg_ReadOnlyVulnerabilityBlock.
  • Container-Backed AlloyDB Omni Coverage: Adds TestAlloyDBOmniToolEndpoints in tests/alloydbomni exercising postgres-sql, postgres-execute-sql, template parameters, list_tables, and pgvector semantic search, and updates .ci/integration.cloudbuild.yaml to trigger alloydb-omni on internal/tools/postgres/ changes.

Security Considerations

  • Test-only and CI configuration changes; parameterizes pg_trigger lookup with $1, sanitizes dynamic identifiers via pgx.Identifier, and adds a defensive cleanup backstop around alloydb_session_read_only=locked verification without modifying production source/tool auth or SQL execution paths.

PR Checklist

  • Make sure to open an issue as a bug/issue before writing your code!
  • Ensure you have manually reviewed the entire diff before requesting a review
  • 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 involves a breaking change

…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.
@gemini-code-assist gemini-code-assist Bot left a comment
Copy link
Copy Markdown
Contributor

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 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.

7ED4

This branch has not been deployed

No deployments
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.

2 participants

0