Skip to content
Draft
6 changes: 6 additions & 0 deletions tests/mongodb/mongodb_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What if a collection is created by another test execution and they are still using it? Dropping the collection here will cause the other test using it to fail.

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"},
Expand Down
2 changes: 1 addition & 1 deletion tests/postgres/postgres_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down
5 changes: 5 additions & 0 deletions tests/singlestore/singlestore_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same here. We should not cause failure in other tests.

}
// Create table
_, err = pool.QueryContext(ctx, createStatement)
if err != nil {
Expand Down
11 changes: 8 additions & 3 deletions tests/trino/trino_integration_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 (
Expand Down Expand Up @@ -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)
}
Expand Down
Loading