pubsub: retry snapshot tests
Snapshot tests flake frequently,
and eventual consistency looks like the culprit.
This CL retries snapshot listing, seeking, and deleting tests.
@@ -20,9 +20,12 @@ import (
"testing"
"time"
+ gax "github.com/googleapis/gax-go"
+
"golang.org/x/net/context"
"cloud.google.com/go/iam"
+ "cloud.google.com/go/internal"
"cloud.google.com/go/internal/testutil"
"google.golang.org/api/iterator"
"google.golang.org/api/option"
@@ -153,28 +156,40 @@ func TestAll(t *testing.T) {
t.Fatalf("CreateSnapshot error: %v", err)
}
- snapIt := client.snapshots(ctx)
+ timeoutCtx, _ = context.WithTimeout(ctx, time.Minute)
+ err = internal.Retry(timeoutCtx, gax.Backoff{}, func() (bool, error) {
+ snapIt := client.snapshots(timeoutCtx)
for {
s, err := snapIt.Next()
if err == nil && s.name == snap.name {
- break
+ return true, nil
}
if err == iterator.Done {
- t.Errorf("cannot find snapshot: %q", snap.name)
- break
+ return false, fmt.Errorf("cannot find snapshot: %q", snap.name)
}
if err != nil {
- t.Error(err)
- break
+ return false, err
+ }
}
+ })
+ if err != nil {
+ t.Error(err)
}
- if err := sub.seekToSnapshot(ctx, snap.snapshot); err != nil {
- t.Errorf("SeekToSnapshot error: %v", err)
+ err = internal.Retry(timeoutCtx, gax.Backoff{}, func() (bool, error) {
+ err := sub.seekToSnapshot(timeoutCtx, snap.snapshot)
+ return err == nil, err
+ })
+ if err != nil {
+ t.Error(err)
}
- if err := snap.delete(ctx); err != nil {
- t.Errorf("DeleteSnap error: %v", err)
+ err = internal.Retry(timeoutCtx, gax.Backoff{}, func() (bool, error) {
+ err := snap.delete(timeoutCtx)
+ return err == nil, err
+ })
+ if err != nil {
+ t.Error(err)
}
if err := sub.Delete(ctx); err != nil {
