Fix token_store_test.go (#7490)

* vault: fix dropped error in test goroutine

* vault: fix dropped test errors
This commit is contained in:
Lars Lehtonen 2019-09-18 14:18:08 -07:00 committed by Brian Kassouf
parent 368eba4055
commit 404cb5f6dd

View file

@ -849,6 +849,9 @@ func TestTokenStore_HandleRequest_RevokeAccessor(t *testing.T) {
ts := exp.tokenStore
rootToken, err := ts.rootToken(namespace.RootContext(nil))
if err != nil {
t.Fatal(err)
}
root := rootToken.ID
testMakeServiceTokenViaBackend(t, ts, root, "tokenid", "", []string{"foo"})
@ -2117,6 +2120,9 @@ func TestTokenStore_HandleRequest_Revoke(t *testing.T) {
ts := exp.tokenStore
rootToken, err := ts.rootToken(namespace.RootContext(nil))
if err != nil {
t.Fatal(err)
}
root := rootToken.ID
testMakeServiceTokenViaBackend(t, ts, root, "child", "", []string{"root", "foo"})
@ -2657,6 +2663,9 @@ func TestTokenStore_HandleRequest_CreateToken_ExistingEntityAlias(t *testing.T)
"mount_accessor": tokenMountAccessor,
},
})
if err != nil {
t.Fatalf("error handling request: %v", err)
}
// Create token role
resp, err = core.HandleRequest(ctx, &logical.Request{
@ -4992,17 +5001,18 @@ func TestTokenStore_RevokeUseCountToken(t *testing.T) {
}
cubbyFuncLock.Unlock()
errCh := make(chan error)
defer close(errCh)
go func() {
cubbyFuncLock.RLock()
err := ts.revokeInternal(namespace.RootContext(nil), saltTut, false)
cubbyFuncLock.RUnlock()
if err == nil {
t.Fatalf("expected error")
}
errCh <- err
}()
// Give time for the function to start and grab locks
time.Sleep(200 * time.Millisecond)
te, err = ts.lookupInternal(namespace.RootContext(nil), saltTut, true, true)
if err != nil {
t.Fatal(err)
@ -5011,8 +5021,10 @@ func TestTokenStore_RevokeUseCountToken(t *testing.T) {
t.Fatal("nil token entry")
}
// Let things catch up
time.Sleep(2 * time.Second)
err = <-errCh
if err == nil {
t.Fatal("expected error on ts.revokeInternal() in anonymous goroutine")
}
// Put back to normal
cubbyFuncLock.Lock()