Skip to content

Commit 2a39d29

Browse files
committed
fix: retries=Infinity
This wasn't tested, and would have looped forever trying to populate this.#timeouts Originally from: tim-kos/node-retry#77
1 parent 90dbd29 commit 2a39d29

2 files changed

Lines changed: 24 additions & 1 deletion

File tree

lib/retry.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -156,8 +156,12 @@ const timeouts = options => {
156156
}
157157

158158
exports.operation = function (options = {}) {
159+
if (options.retries === Infinity) {
160+
options.forever = true
161+
delete options.retries
162+
}
159163
return new RetryOperation(timeouts(options), {
160-
forever: options.forever || (options.retries === Infinity),
164+
forever: options.forever,
161165
unref: options.unref,
162166
maxRetryTime: options.maxRetryTime
163167
})

test/retry.js

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -186,6 +186,25 @@ t.suite('retry', () => {
186186
})
187187
})
188188

189+
t.test('infinite retries', (t, done) => {
190+
const error = new Error('some error')
191+
const operation = retry.operation({ retries: Infinity, minTimeout: 1, maxTimeout: 10 })
192+
let attempts = 0
193+
194+
operation.attempt(function (currentAttempt) {
195+
attempts++
196+
a.equal(currentAttempt, attempts)
197+
if (attempts !== 6 && operation.retry(error)) {
198+
return
199+
}
200+
201+
a.strictEqual(attempts, 6)
202+
a.strictEqual(operation.attempts, attempts)
203+
a.strictEqual(operation.mainError, error)
204+
done()
205+
})
206+
})
207+
189208
t.test('retry forever no retries', (t, done) => {
190209
const error = new Error('some error')
191210
const delay = 50

0 commit comments

Comments
 (0)