Use a channel to signal that the retry go routine and hopefully remove the race condition that makes this a flaky test. (#937)

This commit is contained in:
Phil Kedy 2021-06-11 19:18:00 -04:00 committed by GitHub
parent 14870cb7bc
commit 9cd7de95a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 3 deletions

View File

@ -190,26 +190,28 @@ func TestRetryNotifyRecoverRecovery(t *testing.T) {
func TestRetryNotifyRecoverCancel(t *testing.T) {
config := retry.DefaultConfig()
config.Policy = retry.PolicyExponential
config.InitialInterval = 10 * time.Millisecond
config.Policy = retry.PolicyConstant
config.Duration = 1 * time.Minute
var notifyCalls, recoveryCalls int
ctx, cancel := context.WithCancel(context.Background())
b := config.NewBackOffWithContext(ctx)
errC := make(chan error, 1)
startedC := make(chan struct{}, 100)
go func() {
errC <- retry.NotifyRecover(func() error {
return errRetry
}, b, func(err error, d time.Duration) {
notifyCalls++
startedC <- struct{}{}
}, func() {
recoveryCalls++
})
}()
time.Sleep(1 * time.Second)
<-startedC
cancel()
err := <-errC