Skip to content

Commit

Permalink
Fix dependecy versions.
Browse files Browse the repository at this point in the history
Fix dep versions

Add request dep.

No retries for 204 No Content
  • Loading branch information
Konstantin Kuzmin committed Dec 18, 2018
1 parent 33f9405 commit 7319e88
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 6 deletions.
5 changes: 3 additions & 2 deletions al_util.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,9 @@ let DEFAULT_RETRY = {
* Keeps retrying 5XX HTTP responses and any system level errors
**/
var defaultRetryCb = function(err){
if (err.statusCode >= 500 ||
(err.error && err.error.errno)) {
if (err &&
(err.statusCode >= 500 ||
(err.error && err.error.errno))) {
return true;
} else {
return false;
Expand Down
8 changes: 4 additions & 4 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,12 @@
"timekeeper": "^2.1.2"
},
"dependencies": {
"async": "*",
"debug": "*",
"async": "^2.6.1",
"debug": "^4.1.0",
"moment": "^2.19.2",
"protobufjs": "^6.8.8",
"request": "*",
"request-promise-native": "*",
"request": "^2.88.0",
"request-promise-native": "^1.0.5",
"retry": "^0.12.0"
},
"author": "Alert Logic Inc."
Expand Down
20 changes: 20 additions & 0 deletions test/request_retry_test.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ const assert = require('assert');
const nock = require('nock');
const m_alMock = require('./al_mock');
const m_alService = require('../al_servicec');
const EndpointsC = require('../al_servicec').EndpointsC;

describe('HTTP request retry tests', function() {
beforeEach(function(done) {
Expand Down Expand Up @@ -64,6 +65,25 @@ describe('HTTP request retry tests', function() {
});
});

it('No retries on 204 empty response', function(done) {
nock('https://' + m_alMock.AL_API)
.post('/aims/v1/authenticate')
.reply(200, m_alMock.AIMS_RESPONSE_200);
nock('https://' + m_alMock.AL_API)
.get(/endpoint$/)
.reply(204)
.get(/endpoint$/)
.reply(500, {statusCode: 500});
var aimsc = new m_alService.AimsC(
m_alMock.AL_API, m_alMock.AIMS_CREDS, '/tmp');
var endpointsC = new EndpointsC(m_alMock.AL_API, aimsc, 'cwe');

endpointsC.getEndpoint('azcollect', 'default').then( resp => {
assert.equal(resp, undefined);
done();
});
});

it('Retry 500 with default retry config', function(done) {
this.timeout(4000);
nock('https://' + m_alMock.AL_API)
Expand Down

0 comments on commit 7319e88

Please sign in to comment.