8000 test(source/cassandra): fix cleanup issues and migrate integration tests to testcontainers by emagda97 · Pull Request #4407 · googleapis/mcp-toolbox · GitHub
[go: up one dir, main page]

Skip to content

test(source/cassandra): fix cleanup issues and migrate integration tests to testcontainers - #4407

Open
emagda97 wants to merge 4 commits into
mainfrom
fix/cassandra-testcontainers
Open

emagda97 wants to merge 4 commits into
mainfrom
fix/cassandra-testcontainers

Conversation

@emagda97
@emagda97 emagda97 commented Nov 3, 2026 •
Copy link
Copy Markdown
Collaborator

Description

Fixes three resource-cleanup issues in the Cassandra integration test, then migrates it to testcontainers (following the pattern used for ScyllaDB, CockroachDB, TiDB and others), so CI no longer depends on a long-lived shared Cassandra cluster or its stored credentials.

One commit per change:

  1. Register table cleanup before seeding rows. initTable creates a table and then runs four INSERTs. If an insert failed, t.Fatal fired before the matching defer dropTable was registered, so the table leaked. The drop is now registered via t.Cleanup (with DROP TABLE IF EXISTS) before the table is created.
  2. Report table drop failures. dropTable only log.Printf'd errors, so failed drops never surfaced. They now fail the test with t.Errorf.
  3. Use a per-run keyspace and drop it on cleanup. The fixed example_keyspace was created with IF NOT EXISTS, shared by every run, and never dropped. Each run now uses a UUID-suffixed keyspace that is dropped on cleanup.
  4. Migrate to testcontainers. When CASSANDRA_HOST is unset, the test starts an ephemeral cassandra:5.0.9 container:
    • PasswordAuthenticator is enabled to match the shared cluster, and only the CQL port is published.
    • It creates a dedicated role with a random per-run password, then rotates the default cassandra superuser to a random password.
    • Cleanup is registered at creation, and repeated runs (-count>1) get a fresh container.
    • Setting CASSANDRA_HOST, CASSANDRA_USER and CASSANDRA_PASS still runs the tests against an external cluster.
    • .ci/integration.cloudbuild.yaml: removes the cassandra_user / cassandra_pass / cassandra_host secrets.

Security: no source or tool changes. Test credentials are now generated per run inside an ephemeral container instead of being stored as CI secrets.

Note: retiring the old shared cluster and its secrets is a separate follow-up after merge.

PR Checklist

  • 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 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 involve a breaking change

initTable creates a table and then runs four INSERTs. If any insert
failed, t.Fatal fired before the matching `defer dropTable` was
registered, so the table leaked on the shared cluster.

Register the drop via t.Cleanup before creating each table (using
DROP TABLE IF EXISTS so it is safe if creation itself failed), and
close the session via t.Cleanup so it outlives the table drops.
dropTable only log.Printf'd errors, so failed drops never surfaced and
leaked tables on the shared cluster went unnoticed. Report them with
t.Errorf so a failed teardown fails the test.
The tests used the fixed keyspace example_keyspace, created with IF NOT
EXISTS and never dropped, so every run shared it on the long-lived
cluster and it was never cleaned up.

Generate a UUID-suffixed keyspace per run and drop it via t.Cleanup
after the table drops.
@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 refactors the Cassandra integration tests to dynamically spin up an ephemeral Cassandra container using testcontainers-go when CASSANDRA_HOST is not set, allowing the removal of Cassandra secrets from the Cloud Build configuration. It also improves test isolation with per-run keyspaces and utilizes Go's t.Cleanup for robust resource management. One issue was identified in the container setup where registering a cleanup on a potentially nil container could cause a panic during test teardown.

@emagda97
emagda97 marked this pull request as ready for review November 3, 2026 23:44
@emagda97
emagda97 requested a review from a team as a code owner November 3, 2026 23:44
@emagda97
emagda97 requested a review from Yuan325 November 4, 2026 20:54
Run the Cassandra integration tests against an ephemeral cassandra
container instead of a long-lived shared cluster. Setting CASSANDRA_HOST
(plus CASSANDRA_USER and CASSANDRA_PASS) still runs the tests against an
external cluster.

The container:
- runs cassandra:5.0.9 with PasswordAuthenticator enabled, matching the
  shared cluster, and only the CQL port published,
- waits for the CQL port and the default superuser role to be created,
- provisions a dedicated role with a random per-run password, then
  rotates the default superuser to a random password,
- is cleaned up via testcontainers.CleanupContainer, and the package-level
  connection variables are restored so repeated runs (-count>1) start a
  fresh container.

Drop the CASSANDRA_* secrets from the integration Cloud Build config.
@emagda97
emagda97 force-pushed the fix/cassandra-testcontainers branch from 44f924c to 1af9526 Compare November 4, 2026 21:50
@emagda97
emagda97 requested a review from duwenxin99 November 4, 2026 21:55

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.

3 participants

0