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:
parent
14870cb7bc
commit
9cd7de95a1
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue