Repository navigation
add filter option to retry() and retryable(). PR for #1256. #1261
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
cbc5b4f
0337ee0
0af976c
4367751
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
…t documentation and fixed code based on PR feedback.
- Loading branch information
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -158,7 +158,7 @@ describe("retry", function () { | |
| }); | ||
| }); | ||
|
|
||
| it('retry when all attempts fail and error filter returns true',function(done) { | ||
| it('retry when all attempts fail and error continue test returns true',function(done) { | ||
| var times = 3; | ||
| var callCount = 0; | ||
| var error = 'ERROR'; | ||
|
|
@@ -168,12 +168,12 @@ describe("retry", function () { | |
| callCount++; | ||
| callback(error + callCount, erroredResult + callCount); | ||
| } | ||
| function filter(err) { | ||
| function errorTest(err) { | ||
| return err && err !== special; | ||
| } | ||
| var options = { | ||
| times: times, | ||
| filter: filter | ||
| continueOperation: errorTest | ||
| }; | ||
| async.retry(options, fn, function(err, result){ | ||
| assert.equal(callCount, 3, "did not retry the correct number of times"); | ||
|
|
@@ -183,7 +183,7 @@ describe("retry", function () { | |
| }); | ||
| }); | ||
|
|
||
| it('retry when some attempts fail and error filter returns false at some invokation',function(done) { | ||
| it('retry when some attempts fail and error test returns false at some invokation',function(done) { | ||
| var callCount = 0; | ||
| var error = 'ERROR'; | ||
| var special = 'SPECIAL_ERROR'; | ||
|
|
@@ -193,11 +193,11 @@ describe("retry", function () { | |
| var err = callCount === 2 ? special : error + callCount; | ||
| callback(err, erroredResult + callCount); | ||
| } | ||
| function filter(err) { | ||
| function errorTest(err) { | ||
| return err && err === error + callCount; // just a different pattern | ||
| } | ||
| var options = { | ||
| filter: filter | ||
| continueOperation: errorTest | ||
| }; | ||
| async.retry(options, fn, function(err, result){ | ||
| assert.equal(callCount, 2, "did not retry the correct number of times"); | ||
|
|
@@ -207,7 +207,7 @@ describe("retry", function () { | |
| }); | ||
| }); | ||
|
|
||
| it('retry with interval when some attempts fail and error filter returns false at some invokation',function(done) { | ||
| it('retry with interval when some attempts fail and error test returns false at some invokation',function(done) { | ||
| var interval = 50; | ||
| var callCount = 0; | ||
| var error = 'ERROR'; | ||
|
|
@@ -219,11 +219,11 @@ describe("retry", function () { | |
| var err = callCount === specialCount ? special : error + callCount; | ||
| callback(err, erroredResult + callCount); | ||
| } | ||
| function filter(err) { | ||
| function errorTest(err) { | ||
| return err && err !== special; | ||
| } | ||
| var start = new Date().getTime(); | ||
| async.retry({ interval: interval, filter: filter }, fn, function(err, result){ | ||
| async.retry({ interval: interval, continueOperation: errorTest }, fn, function(err, result){ | ||
| var now = new Date().getTime(); | ||
| var duration = now - start; | ||
| assert(duration >= (interval * (specialCount - 1)), 'did not include interval'); | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is a bit fragile of a test
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. hi, can you elaborate? Do you mean the specific assertion? I based it on existing test. Just checks that the appropriate time has passed?
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. its probably fine, we have just seen issues lately with some tests erring out (especially in CI) due to slight timing issues |
||
|
|
@@ -234,26 +234,26 @@ describe("retry", function () { | |
| }); | ||
| }); | ||
|
|
||
| it('retry when first attempt succeeds and error filter should not be called',function(done) { | ||
| it('retry when first attempt succeeds and error test should not be called',function(done) { | ||
| var callCount = 0; | ||
| var error = 'ERROR'; | ||
| var erroredResult = 'RESULT'; | ||
| var filterCalled = false; | ||
| var continueTestCalled = false; | ||
| function fn(callback) { | ||
| callCount++; | ||
| callback(null, erroredResult + callCount); | ||
| } | ||
| function filter(err) { | ||
| filterCalled = true; | ||
| function errorTest(err) { | ||
| continueTestCalled = true; | ||
| return err && err === error; | ||
| } | ||
| var options = { | ||
| filter: filter | ||
| continueOperation: errorTest | ||
| }; | ||
| async.retry(options, fn, _.rest(function(args) { | ||
| assert.equal(callCount, 1, "did not retry the correct number of times"); | ||
| expect(args).to.be.eql([null, erroredResult + callCount]); | ||
| assert.equal(filterCalled, false, "filter function was called"); | ||
| assert.equal(continueTestCalled, false, "error test function was called"); | ||
| done(); | ||
| })); | ||
| }); | ||
|
|
||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
isn't it invoked with
(error, ...any other arguments)