Пример #1
0
						retryPolicy.DelayForStub = func(failedAttempts uint) (time.Duration, bool) {
							Ω(attempts()).Should(Equal(int(failedAttempts)))

							select {
							case d, ok := <-durations:
								return d, ok
							}
						}
					})

					It("continuously retries with an increasing attempt count", func() {
						Ω(retryPolicy.DelayForCallCount()).Should(Equal(4))
						Ω(sleeper.SleepCallCount()).Should(Equal(3))

						Ω(retryPolicy.DelayForArgsForCall(0)).Should(Equal(uint(1)))
						Ω(sleeper.SleepArgsForCall(0)).Should(Equal(time.Second))

						Ω(retryPolicy.DelayForArgsForCall(1)).Should(Equal(uint(2)))
						Ω(sleeper.SleepArgsForCall(1)).Should(Equal(2 * time.Second))

						Ω(retryPolicy.DelayForArgsForCall(2)).Should(Equal(uint(3)))
						Ω(sleeper.SleepArgsForCall(2)).Should(Equal(1000 * time.Second))

						Ω(errResult).Should(Equal(retryableError))
					})
				})
			})
		}

		Context("when the error is not retryable", func() {
						retryPolicy.DelayForStub = func(failedAttempts uint) (time.Duration, bool) {
							Expect(attempts()).To(Equal(int(failedAttempts)))

							select {
							case d, ok := <-durations:
								return d, ok
							}
						}
					})

					It("continuously retries with an increasing attempt count", func() {
						Expect(retryPolicy.DelayForCallCount()).To(Equal(4))
						Expect(sleeper.SleepCallCount()).To(Equal(3))

						Expect(retryPolicy.DelayForArgsForCall(0)).To(Equal(uint(1)))
						Expect(sleeper.SleepArgsForCall(0)).To(Equal(time.Second))

						Expect(retryPolicy.DelayForArgsForCall(1)).To(Equal(uint(2)))
						Expect(sleeper.SleepArgsForCall(1)).To(Equal(2 * time.Second))

						Expect(retryPolicy.DelayForArgsForCall(2)).To(Equal(uint(3)))
						Expect(sleeper.SleepArgsForCall(2)).To(Equal(1000 * time.Second))

						Expect(errResult).To(Equal(retryableError))
					})
				})
			})
		}

		Context("when the error is not retryable", func() {