summaryrefslogtreecommitdiff
path: root/deps/npm/node_modules/npm-registry-client/node_modules/retry/test/integration/test-retry-operation.js
diff options
context:
space:
mode:
Diffstat (limited to 'deps/npm/node_modules/npm-registry-client/node_modules/retry/test/integration/test-retry-operation.js')
-rw-r--r--deps/npm/node_modules/npm-registry-client/node_modules/retry/test/integration/test-retry-operation.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/deps/npm/node_modules/npm-registry-client/node_modules/retry/test/integration/test-retry-operation.js b/deps/npm/node_modules/npm-registry-client/node_modules/retry/test/integration/test-retry-operation.js
index cecfa3b731..916936424f 100644
--- a/deps/npm/node_modules/npm-registry-client/node_modules/retry/test/integration/test-retry-operation.js
+++ b/deps/npm/node_modules/npm-registry-client/node_modules/retry/test/integration/test-retry-operation.js
@@ -104,3 +104,73 @@ var retry = require(common.dir.lib + '/retry');
fn();
})();
+
+(function testRetryForeverNoRetries() {
+ var error = new Error('some error');
+ var delay = 50
+ var operation = retry.operation({
+ retries: null,
+ forever: true,
+ minTimeout: delay,
+ maxTimeout: delay
+ });
+
+ var attempts = 0;
+ var startTime = new Date().getTime();
+
+ var finalCallback = fake.callback('finalCallback');
+ fake.expectAnytime(finalCallback);
+
+ var fn = function() {
+ operation.attempt(function(currentAttempt) {
+ attempts++;
+ assert.equal(currentAttempt, attempts);
+ if (attempts !== 4 && operation.retry(error)) {
+ return;
+ }
+
+ var endTime = new Date().getTime();
+ var minTime = startTime + (delay * 3);
+ var maxTime = minTime + 20 // add a little headroom for code execution time
+ assert(endTime > minTime)
+ assert(endTime < maxTime)
+ assert.strictEqual(attempts, 4);
+ assert.strictEqual(operation.attempts(), attempts);
+ assert.strictEqual(operation.mainError(), error);
+ finalCallback();
+ });
+ };
+
+ fn();
+})();
+
+(function testStop() {
+ var error = new Error('some error');
+ var operation = retry.operation([1, 2, 3]);
+ var attempts = 0;
+
+ var finalCallback = fake.callback('finalCallback');
+ fake.expectAnytime(finalCallback);
+
+ var fn = function() {
+ operation.attempt(function(currentAttempt) {
+ attempts++;
+ assert.equal(currentAttempt, attempts);
+
+ if (attempts === 2) {
+ operation.stop();
+
+ assert.strictEqual(attempts, 2);
+ assert.strictEqual(operation.attempts(), attempts);
+ assert.strictEqual(operation.mainError(), error);
+ finalCallback();
+ }
+
+ if (operation.retry(error)) {
+ return;
+ }
+ });
+ };
+
+ fn();
+})();