Comparing version 1.0.1 to 1.1.0
{ | ||
"name": "rerun", | ||
"description": "A retry library for node.js", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"author": "BigPanda <noam@bigpanda.io>", | ||
@@ -6,0 +6,0 @@ "repository": { |
@@ -11,2 +11,3 @@ var Q = require('q'); | ||
var userRejectError = options.rejectError || RejectError; | ||
var randomizeRetry = options.retryRandom || false; | ||
@@ -21,3 +22,4 @@ function _succeed(returned) { | ||
} else { | ||
Q.delay(timeout).then(function () { return toRetry() }).then(_succeed, _failed); | ||
var timeToWait = randomizeRetry ? Math.random() * (timeout / 2) + (timeout / 2) : timeout; | ||
Q.delay(timeToWait).then(function () { return toRetry() }).then(_succeed, _failed); | ||
timeout *= factor; | ||
@@ -24,0 +26,0 @@ } |
@@ -118,2 +118,24 @@ var chai = require('chai'); | ||
}); | ||
it('should randomize time', function (done) { | ||
var id = { complicated: 'id' }; | ||
var data = [ | ||
{ foo: 'bar' } | ||
]; | ||
var array = [ | ||
{ id: id, data: data } | ||
]; | ||
nock('http://localhost:3027').post('/test', JSON.stringify({ objects: array })).times(1).reply(401); | ||
var scope = nock('http://localhost:3027').post('/test', JSON.stringify({ objects: array })).reply(200); | ||
var promise = request({ url: 'http://localhost:3027/test', json: { objects: array }, retries: 2, retryFactor: 2, retryTimeout: 200, retryRandom: true, method: 'POST' }); | ||
var timeBefore = new Date().getTime(); | ||
promise.then(function () { | ||
expect(new Date().getTime() - timeBefore).to.lte(200).and.to.gte(100); | ||
scope.done(); | ||
done(); | ||
}, function (err) { | ||
done(err); | ||
}); | ||
}); | ||
}); |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
18884
182