Closed wizo06 closed 4 years ago
Merging #75 into master will decrease coverage by
0.06%
. The diff coverage is100.00%
.
@@ Coverage Diff @@
## master #75 +/- ##
==========================================
- Coverage 90.41% 90.34% -0.07%
==========================================
Files 2 2
Lines 146 145 -1
==========================================
- Hits 132 131 -1
Misses 14 14
Impacted Files | Coverage Δ | |
---|---|---|
lib/retry_operation.js | 86.31% <100.00%> (-0.15%) |
:arrow_down: |
Continue to review full report at Codecov.
Legend - Click here to learn more
Δ = absolute <relative> (impact)
,ø = not affected
,? = missing data
Powered by Codecov. Last update b316bfc...85f814b. Read the comment docs.
The problem:
retryOperation.reset()
is not resetting properly.Context
According to the documentation,
retryOperation.reset()
is supposed to:The way
node-retry
works is by creating an array with a length ofn
, wheren
is the number of retries. This array is stored in two variables,this._originalTimeouts
andthis._timeouts
. Each element in this array, is the interval (in milliseconds) in-between each retry/attempt. Then-th
attempt is initialized inthis._attempts = 1;
.For each retry/attempt,
this._attempts
is increased by1
, andthis._timeouts
is.shift()
'ed.When
retryOperation.reset()
is called,this._attempts
is reverted back to1
, andthis._timeouts
is restored by referencingthis._originalTimeouts
.Arrays in Javascript are mutable, which means
this._timeouts = this._originalTimeouts;
does not make a new copy ofthis._originalTimeouts
intothis._timeouts
. Therefore, whenthis._timeouts
is.shift()
'ed,this._originalTimeouts
also gets.shift()
'ed, resulting in the loss of the intervals inthis._originalTimeouts
.The solution
Make a new copy of
this._originalTimeouts
and then assign it tothis._timeouts
.Before
After
Reference
Read more about
.shift()
here Read more about.slice()
here Read more about mutable here