Fix flaky test

This commit is contained in:
Alex Dadgar
2017-01-26 13:02:13 -08:00
parent 421c982ea1
commit 87c9859db6

View File

@@ -591,9 +591,6 @@ func TestVaultClient_LookupToken_RateLimit(t *testing.T) {
unblock := make(chan struct{})
for i := 0; i < numRequests; i++ {
go func() {
// Ensure all the goroutines are made
time.Sleep(10 * time.Millisecond)
// Lookup ourselves
_, err := client.LookupToken(ctx, v.Config.Token)
if err != nil {
@@ -607,7 +604,7 @@ func TestVaultClient_LookupToken_RateLimit(t *testing.T) {
// Cancel the context
cancel()
time.AfterFunc(1*time.Second, func() { close(unblock) })
close(unblock)
}()
}
@@ -618,9 +615,15 @@ func TestVaultClient_LookupToken_RateLimit(t *testing.T) {
}
desired := numRequests - 1
if cancels != desired {
t.Fatalf("Incorrect number of cancels; got %d; want %d", cancels, desired)
}
testutil.WaitForResult(func() (bool, error) {
if cancels != desired {
return false, fmt.Errorf("Incorrect number of cancels; got %d; want %d", cancels, desired)
}
return true, nil
}, func(err error) {
t.Fatalf("Connection not established")
})
}
func TestVaultClient_CreateToken_Root(t *testing.T) {