diff options
author | Alex Ianus <hire@alexianus.com> | 2016-05-18 15:31:38 -0400 |
---|---|---|
committer | Alex Ianus <hire@alexianus.com> | 2016-05-18 15:31:38 -0400 |
commit | c99b97e20ef9e38f78da19f3a1fa48f6deda2c33 (patch) | |
tree | 9d12c92e89961a3fab5008422078217772d998ff /mocha_test | |
parent | 9f03d5d630e467d3d3ec995d3610b967458de387 (diff) | |
download | async-c99b97e20ef9e38f78da19f3a1fa48f6deda2c33.tar.gz |
Allow custom retry interval
Diffstat (limited to 'mocha_test')
-rw-r--r-- | mocha_test/retry.js | 26 |
1 files changed, 24 insertions, 2 deletions
diff --git a/mocha_test/retry.js b/mocha_test/retry.js index 2aa48e8..43a8f6f 100644 --- a/mocha_test/retry.js +++ b/mocha_test/retry.js @@ -23,7 +23,7 @@ describe("retry", function () { }); }); - it('retry when all attempts succeeds',function(done) { + it('retry when all attempts fail',function(done) { var times = 3; var callCount = 0; var error = 'ERROR'; @@ -53,7 +53,7 @@ describe("retry", function () { done(); }); - it('retry with interval when all attempts succeeds',function(done) { + it('retry with interval when all attempts fail',function(done) { var times = 3; var interval = 50; var callCount = 0; @@ -75,6 +75,28 @@ describe("retry", function () { }); }); + it('retry with custom interval when all attempts fail',function(done) { + var times = 3; + var intervalFunc = function(retryCount) { return retryCount * 100; }; + var callCount = 0; + var error = 'ERROR'; + var erroredResult = 'RESULT'; + function fn(callback) { + callCount++; + callback(error + callCount, erroredResult + callCount); // respond with indexed values + } + var start = new Date().getTime(); + async.retry({ times: times, interval: intervalFunc}, fn, function(err, result){ + var now = new Date().getTime(); + var duration = now - start; + assert(duration >= 300, 'did not include custom interval'); + assert.equal(callCount, 3, "did not retry the correct number of times"); + assert.equal(err, error + times, "Incorrect error was returned"); + assert.equal(result, erroredResult + times, "Incorrect result was returned"); + done(); + }); + }); + it("should not require a callback", function (done) { var called = false; async.retry(3, function(cb) { |