func tryInBackground(monitRetryStrategy boshretry.RetryStrategy) chan error { errChan := make(chan error) go func() { errChan <- monitRetryStrategy.Try() }() return errChan }
sleepForIncrements(timeService, maxOtherAttempts, delay) Eventually(errChan).Should(Receive(Equal(lastError))) Expect(retryable.Response().Body.(ClosedChecker).Closed()).To(BeTrue()) }) }) }) It("waits for retry delay between retries", func() { for i := 0; i < maxUnavailableAttempts+maxOtherAttempts; i++ { retryable.AddAttemptBehavior(unavailable, true, nil) } go func() { monitRetryStrategy.Try() }() Eventually(retryable.Attempts).Should(Equal(1)) timeService.Increment(delay - time.Millisecond) Consistently(retryable.Attempts).Should(Equal(1)) timeService.Increment(2 * time.Millisecond) Eventually(retryable.Attempts).Should(Equal(2)) }) Context("when error is not due to failed response", func() { It("retries until maxOtherAttempts are exhausted", func() { for i := 0; i < maxOtherAttempts-1; i++ { retryable.AddAttemptBehavior(nil, true, errors.New("request error")) } retryable.AddAttemptBehavior(nil, true, lastError)