Skip to content

Commit 75e928a

Browse files
committed
Added pre-cleanup function call and addressed GCA suggestions
1 parent d7244d6 commit 75e928a

File tree

2 files changed

+9
-4
lines changed

2 files changed

+9
-4
lines changed

tests/common.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1143,23 +1143,23 @@ func CleanupSpannerResources(t *testing.T, ctx context.Context, adminClient *dat
11431143
if err := gIter.Do(func(row *spanner.Row) error {
11441144
var name string
11451145
if err := row.Column(0, &name); err == nil {
1146-
ddlStatements = append(ddlStatements, fmt.Sprintf("DROP PROPERTY GRAPH `%s` ", name))
1146+
ddlStatements = append(ddlStatements, fmt.Sprintf("DROP PROPERTY GRAPH IF EXISTS %s", name))
11471147
}
11481148
return nil
11491149
}); err != nil {
11501150
t.Errorf("Cleanup: failed to iterate graphs: %v", err)
11511151
}
11521152

11531153
//Identify Tables
1154-
tableQuery := `SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '' AND table_name LIKE @pattern`
1154+
tableQuery := `SELECT table_name FROM INFORMATION_SCHEMA.TABLES WHERE table_schema = '' AND table_name LIKE @pattern ORDER BY PARENT_TABLE_NAME DESC`
11551155
tIter := dataClient.Single().Query(ctx, spanner.Statement{
11561156
SQL: tableQuery,
11571157
Params: map[string]any{"pattern": pattern},
11581158
})
11591159
if err := tIter.Do(func(row *spanner.Row) error {
11601160
var name string
11611161
if err := row.Column(0, &name); err == nil {
1162-
ddlStatements = append(ddlStatements, fmt.Sprintf("DROP TABLE `%s` ", name))
1162+
ddlStatements = append(ddlStatements, fmt.Sprintf("DROP TABLE IF EXISTS %s", name))
11631163
}
11641164
return nil
11651165
}); err != nil {

tests/spanner/spanner_integration_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -102,8 +102,13 @@ func TestSpannerToolEndpoints(t *testing.T) {
102102
SpannerDatabase,
103103
)
104104

105+
t.Log("Wiping stale test resources from database...")
106+
tests.CleanupSpannerResources(t, ctx, adminClient, dataClient, dbString, "")
107+
105108
t.Cleanup(func() {
106-
tests.CleanupSpannerResources(t, context.Background(), adminClient, dataClient, dbString, uniqueID)
109+
cleanupCtx, cancel := context.WithTimeout(context.Background(), 5*time.Minute)
110+
defer cancel()
111+
tests.CleanupSpannerResources(t, cleanupCtx, adminClient, dataClient, dbString, uniqueID)
107112
})
108113

109114
t.Logf("DEBUG: Starting test run with isolated ID: %s", uniqueID)

0 commit comments

Comments
 (0)