Handle "invalid request" failures stemming from a kvv2 upgrade. (#9550)

This commit is contained in:
ncabatoff 2020-07-22 10:56:00 -04:00 committed by GitHub
parent de3d78ba39
commit 7484fd7c72
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 18 additions and 9 deletions

View File

@ -1,6 +1,7 @@
package vault
import (
"errors"
"strings"
"testing"
"time"
@ -78,15 +79,23 @@ func TestCoreMetrics_KvSecretGauge(t *testing.T) {
}
}
for _, p := range v2secrets {
req := logical.TestRequest(t, logical.CreateOperation, p)
req.Data["data"] = map[string]interface{}{"foo": "bar"}
req.ClientToken = root
resp, err := core.HandleRequest(ctx, req)
if err != nil {
t.Fatalf("err: %v", err)
}
if resp.Error() != nil {
t.Fatalf("bad: %#v", resp)
for i := 0; i < 50; i++ {
req := logical.TestRequest(t, logical.CreateOperation, p)
req.Data["data"] = map[string]interface{}{"foo": "bar"}
req.ClientToken = root
resp, err := core.HandleRequest(ctx, req)
if err != nil {
if errors.Is(err, logical.ErrInvalidRequest) {
// Handle scenario where KVv2 upgrade is ongoing
time.Sleep(100 * time.Millisecond)
continue
}
t.Fatalf("err: %v", err)
}
if resp.Error() != nil {
t.Fatalf("bad: %#v", resp)
}
break
}
}