test(asset): increase BQ retries
@@ -49,18 +49,21 @@ func TestMain(t *testing.T) {
tablePrefix := "client_library_table"
createDataset(ctx, t, client, datasetID)
+ testutil.Retry(t, 5, 10*time.Second, func(r *testutil.R) {
stdOut, stdErr, err := m.Run(env, 2*time.Minute, fmt.Sprintf("--scope=%s", scope), fmt.Sprintf("--fullResourceName=%s", fullResourceName), fmt.Sprintf("--dataset=%s", dataset), fmt.Sprintf("--tablePrefix=%s", tablePrefix))
if err != nil {
- t.Errorf("execution failed: %v", err)
+ r.Errorf("execution failed: %v", err)
+ return
}
if len(stdErr) > 0 {
- t.Errorf("did not expect stderr output, got %d bytes: %s", len(stdErr), string(stdErr))
+ r.Errorf("did not expect stderr output, got %d bytes: %s", len(stdErr), string(stdErr))
}
got := string(stdOut)
if !strings.Contains(got, dataset) {
- t.Errorf("stdout returned %s, wanted to contain %s", got, dataset)
+ r.Errorf("stdout returned %s, wanted to contain %s", got, dataset)
}
+ })
}
func createDataset(ctx context.Context, t *testing.T, client *bigquery.Client, datasetID string) {
@@ -86,15 +89,22 @@ func createDataset(ctx context.Context, t *testing.T, client *bigquery.Client, d
time.Sleep(10 * time.Second) // Extra time to let the delete settle.
+ testutil.Retry(t, 10, 10*time.Second, func(r *testutil.R) {
meta := &bigquery.DatasetMetadata{
- Location: "US", // See https://cloud.google.com/bigquery/docs/locations
+ Location: "US", // See https://cloud.google.com/bigquery/docs/locations.
}
if err := client.Dataset(datasetID).Create(ctx, meta); err != nil {
- if err, ok := err.(*googleapi.Error); ok {
- if err.Code == 409 { // Already exists. Not sure why.
+ if err, ok := err.(*googleapi.Error); ok && err.Code == 409 {
+ // Already exists. Not sure why.
+ if err := d.DeleteWithContents(ctx); err != nil {
+ if err, ok := err.(*googleapi.Error); ok && err.Code != 404 {
+ // Check 404 just in case a delete was slow to propagate.
+ r.Errorf("Dataset.Delete(%q): %v", datasetID, err)
return
}
}
- t.Fatalf("Dataset.Create(%q): %v", datasetID, err)
}
+ r.Errorf("Dataset.Create(%q): %v", datasetID, err)
+ }
+ })
}
