test(iam): Add Retry to TestServiceAccounts
Attempt to fix occasional test flakes apparently caused by eventual consistency of recently created Service Account with retry of renameServiceAccount.
Fixes:
@@ -18,6 +18,7 @@ import (
"bytes"
"strings"
"testing"
+ "time"
"github.com/GoogleCloudPlatform/golang-samples/internal/testutil"
"github.com/gofrs/uuid"
@@ -41,14 +42,18 @@ func TestServiceAccounts(t *testing.T) {
}
// renameServiceAccount test.
+
+ testutil.Retry(t, 5, 5*time.Second, func(r *testutil.R) {
account, err = renameServiceAccount(buf, account.Email, "Updated Test")
if err != nil {
- t.Fatalf("renameServiceAccount: %v", err)
+ r.Errorf("renameServiceAccount: %v", err)
+ return
}
wantDispName := "Updated Test"
if wantDispName != account.DisplayName {
- t.Fatalf("renameServiceAccount: account.DisplayName is %q, wanted %q", account.Name, wantDispName)
+ r.Errorf("renameServiceAccount: account.DisplayName is %q, wanted %q", account.Name, wantDispName)
}
+ })
// disableServiceAccount test.
err = disableServiceAccount(buf, account.Email)
