diff --git a/tests/mongodb/mongodb_integration_test.go b/tests/mongodb/mongodb_integration_test.go index 3d84837de8a..5a1b76456ab 100644 --- a/tests/mongodb/mongodb_integration_test.go +++ b/tests/mongodb/mongodb_integration_test.go @@ -446,10 +446,16 @@ func runToolAggregateInvokeTest(t *testing.T, aggregate1Want string, aggregateMa func setupMongoDB(t *testing.T, ctx context.Context, database *mongo.Database) func(*testing.T) { collectionName := "test_collection" + //Ensure the collection is clean if err := database.Collection(collectionName).Drop(ctx); err != nil { t.Logf("Warning: failed to drop collection before setup: %v", err) } + // Drop the target collection used in aggregate tests + if err := database.Collection("target_collection").Drop(ctx); err != nil { + t.Logf("Warning: failed to drop target collection before setup: %v", err) + } + documents := []map[string]any{ {"_id": 1, "id": 1, "name": "Alice", "email": ServiceAccountEmail}, {"_id": 14, "id": 2, "name": "FakeAlice", "email": "fakeAlice@gmail.com"}, diff --git a/tests/postgres/postgres_integration_test.go b/tests/postgres/postgres_integration_test.go index 273c6f30149..466440fd95e 100644 --- a/tests/postgres/postgres_integration_test.go +++ b/tests/postgres/postgres_integration_test.go @@ -93,7 +93,7 @@ func TestPostgres(t *testing.T) { t.Fatalf("unable to create postgres connection pool: %s", err) } - // cleanup test environment + // cleanup the collections tests.CleanupPostgresTables(t, ctx, pool) // create table name with UUID diff --git a/tests/serverlessspark/serverless_spark_integration_test.go b/tests/serverlessspark/serverless_spark_integration_test.go index c2f245dc4fa..6bdbbce572e 100644 --- a/tests/serverlessspark/serverless_spark_integration_test.go +++ b/tests/serverlessspark/serverless_spark_integration_test.go @@ -660,7 +660,7 @@ func runCancelBatchTest(t *testing.T, client *dataproc.BatchControllerClient, ct } if batch.State != dataprocpb.Batch_SUCCEEDED { - waitForBatch(t, client, ctx, batchName, []dataprocpb.Batch_State{dataprocpb.Batch_CANCELLING, dataprocpb.Batch_CANCELLED}, 2*time.Minute) + waitForBatch(t, client, ctx, batchName, []dataprocpb.Batch_State{dataprocpb.Batch_CANCELLING, dataprocpb.Batch_CANCELLED}, 5*time.Minute) } } diff --git a/tests/singlestore/singlestore_integration_test.go b/tests/singlestore/singlestore_integration_test.go index 28419d49f35..2f6b17f3eb3 100644 --- a/tests/singlestore/singlestore_integration_test.go +++ b/tests/singlestore/singlestore_integration_test.go @@ -109,6 +109,11 @@ func setupSingleStoreTable(t *testing.T, ctx context.Context, pool *sql.DB, crea t.Fatalf("unable to connect to test database: %s", err) } + // Safety drop before creation + _, err = pool.ExecContext(ctx, fmt.Sprintf("DROP TABLE IF EXISTS %s;", tableName)) + if err != nil { + t.Fatalf("Warning: failed to drop table %s before creation:%v ", tableName, err) + } // Create table _, err = pool.QueryContext(ctx, createStatement) if err != nil { diff --git a/tests/trino/trino_integration_test.go b/tests/trino/trino_integration_test.go index 126e887b22d..9874fd98247 100644 --- a/tests/trino/trino_integration_test.go +++ b/tests/trino/trino_integration_test.go @@ -27,7 +27,6 @@ import ( "github.com/google/uuid" "github.com/googleapis/genai-toolbox/internal/testutils" "github.com/googleapis/genai-toolbox/tests" - _ "github.com/trinodb/trino-go-client/trino" // Import Trino SQL driver ) var ( @@ -163,15 +162,21 @@ func setupTrinoTable(t *testing.T, ctx context.Context, pool *sql.DB, createStat if err != nil { t.Fatalf("unable to connect to test database: %s", err) } + //Ensure the collection is clean + _, err = pool.ExecContext(ctx, fmt.Sprintf("DROP TABLE IF EXISTS %s", tableName)) + if err != nil { + t.Logf("Warning: failed to drop existing table %s", tableName) + } // Create table - _, err = pool.QueryContext(ctx, createStatement) + _, err = pool.ExecContext(ctx, createStatement) + if err != nil { t.Fatalf("unable to create test table %s: %s", tableName, err) } // Insert test data - _, err = pool.QueryContext(ctx, insertStatement, params...) + _, err = pool.ExecContext(ctx, insertStatement, params...) if err != nil { t.Fatalf("unable to insert test data: %s", err) }