File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -156,8 +156,12 @@ const timeouts = options => {
156156}
157157
158158exports . 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 } )
Original file line number Diff line number Diff 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
You can’t perform that action at this time.
0 commit comments