Skip to content

Commit

Permalink
added similar test cases.
Browse files Browse the repository at this point in the history
  • Loading branch information
yog27ray committed Jan 14, 2020
1 parent adfd4b0 commit 4eeb2cc
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 1 deletion.
3 changes: 2 additions & 1 deletion lib/constants.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var Constants = {
'ERROR_NOT_REGISTERED' : 'NotRegistered',
'ERROR_MESSAGE_TOO_BIG' : 'MessageTooBig',
'ERROR_MISSING_COLLAPSE_KEY' : 'MissingCollapseKey',
'ERROR_UNAVAILABLE' : 'Unavailable'
'ERROR_UNAVAILABLE' : 'Unavailable',
'ERROR_INTERNAL_SERVER_ERROR' : 'InternalServerError'

/** END DEPRECATED **/
};
Expand Down
52 changes: 52 additions & 0 deletions test/unit/senderSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -703,6 +703,22 @@ describe('UNIT Sender', function () {
}, callback);
});

it('should retry if some regTokens were failed with InternalServerError', function (done) {
var callback = function () {
expect(args.tries).to.equal(3);
// Last call of sendNoRetry should be for only failed regTokens
expect(args.reg_tokens.length).to.equal(1);
expect(args.reg_tokens[0]).to.equal(3);
done();
};
var sender = new Sender('myKey');
setArgs(null, [{ results: [{}, { error: 'InternalServerError' }, { error: 'InternalServerError' }]}, { results: [ {}, { error: 'InternalServerError' } ] }, { results: [ {} ] } ]);
sender.send({ data: {}}, [1,2,3], {
retries: 5,
backoff: 100
}, callback);
});

it('should retry all regTokens in event of an error', function (done) {
var start = new Date();
var callback = function () {
Expand Down Expand Up @@ -731,6 +747,22 @@ describe('UNIT Sender', function () {
sender.send({ data: {}}, [1,2,3], 3, callback);
});

it('should update the failures and successes correctly when retrying for InternalServerError response', function (done) {
var callback = function(error, response) {
expect(error).to.equal(null);
expect(response.canonical_ids).to.equal(1);
expect(response.success).to.equal(2);
expect(response.failure).to.equal(0);
done();
};
var sender = new Sender('myKey');
setArgs(null, [
{ success: 1, failure: 2, canonical_ids: 0, results: [ {}, { error: 'InternalServerError' }, { error: 'InternalServerError' } ] },
{ success: 1, canonical_ids: 1, failure: 0, results: [ {}, {} ] }
]);
sender.send({ data: {}}, [1,2,3], 3, callback);
});

it('should update the failures and successes correctly when retrying and failing some', function (done) {
var callback = function(error, response) {
expect(error).to.equal(null);
Expand All @@ -750,5 +782,25 @@ describe('UNIT Sender', function () {
backoff: 100
}, callback);
});

it('should update the failures and successes correctly when retrying and failing some with InternalServerError response', function (done) {
var callback = function(error, response) {
expect(error).to.equal(null);
expect(response.canonical_ids).to.equal(0);
expect(response.success).to.equal(1);
expect(response.failure).to.equal(2);
done();
};
var sender = new Sender('myKey');
setArgs(null, [
{ success: 0, failure: 3, canonical_ids: 0, results: [ { error: 'InternalServerError' }, { error: 'InternalServerError' }, { error: 'InternalServerError' } ] },
{ success: 1, canonical_ids: 0, failure: 2, results: [ { error: 'InternalServerError' }, { error: 'InternalServerError' }, {} ] },
{ success: 0, canonical_ids: 0, failure: 2, results: [ { error: 'InternalServerError' }, { error: 'InternalServerError' } ] }
]);
sender.send({ data: {}}, [1,2,3], {
retries: 3,
backoff: 100
}, callback);
});
});
});

0 comments on commit 4eeb2cc

Please sign in to comment.