bigquery: retry Tables test
This test is flaky (about 5%) because apparently it can take some time
for a new table to appear in the listing of a dataset's tables.
Add retry logic to the test. This brings the flakiness to ~0.
@@ -225,7 +225,12 @@ func TestIntegration_Tables(t *testing.T) {
ctx := context.Background()
table := newTable(t, schema)
defer table.Delete(ctx)
+ wantName := table.FullyQualifiedName()
+ // This test is flaky due to eventual consistency.
+ ctx, cancel := context.WithTimeout(ctx, 10*time.Second)
+ defer cancel()
+ err := internal.Retry(ctx, gax.Backoff{}, func() (stop bool, err error) {
// Iterate over tables in the dataset.
it := dataset.Tables(ctx)
var tableNames []string
@@ -235,23 +240,22 @@ func TestIntegration_Tables(t *testing.T) {
break
}
if err != nil {
- t.Fatal(err)
+ return false, err
}
tableNames = append(tableNames, tbl.FullyQualifiedName())
}
// Other tests may be running with this dataset, so there might be more
// than just our table in the list. So don't try for an exact match; just
// make sure that our table is there somewhere.
- found := false
- wantName := table.FullyQualifiedName()
for _, tn := range tableNames {
if tn == wantName {
- found = true
- break
+ return true, nil
}
}
- if !found {
- t.Errorf("got %v\nwant %s in the list", tableNames, wantName)
+ return false, fmt.Errorf("got %v\nwant %s in the list", tableNames, wantName)
+ })
+ if err != nil {
+ t.Fatal(err)
}
}
