From 404cb5f6dd56657b385809333eeaab67f5957248 Mon Sep 17 00:00:00 2001 From: Lars Lehtonen Date: Wed, 18 Sep 2019 14:18:08 -0700 Subject: [PATCH] Fix token_store_test.go (#7490) * vault: fix dropped error in test goroutine * vault: fix dropped test errors --- vault/token_store_test.go | 22 +++++++++++++++++----- 1 file changed, 17 insertions(+), 5 deletions(-) diff --git a/vault/token_store_test.go b/vault/token_store_test.go index d03975d30..4b16409eb 100644 --- a/vault/token_store_test.go +++ b/vault/token_store_test.go @@ -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()