Skip to content

Commit

Permalink
Merge 146253b into c83bbfb
Browse files Browse the repository at this point in the history
  • Loading branch information
joshsammut committed Jun 18, 2020
2 parents c83bbfb + 146253b commit 2fcea81
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
2 changes: 1 addition & 1 deletion src/EurekaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -606,7 +606,7 @@ export default class Eureka extends EventEmitter {
// Perform retry if request failed and we have attempts left
const responseInvalid = response
&& response.statusCode
&& String(response.statusCode)[0] === '5';
&& response.statusCode >= 400;

if ((error || responseInvalid) && retryAttempt < this.config.eureka.maxRetries) {
const nextRetryDelay = this.config.eureka.requestRetryDelay * (retryAttempt + 1);
Expand Down
8 changes: 5 additions & 3 deletions test/EurekaClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -1099,7 +1099,7 @@ describe('Eureka client', () => {
const overrides = {
eureka: {
serviceUrls: {
default: ['http://serverA', 'http://serverB'],
default: ['http://serverA', 'http://serverB', 'http://serverC'],
},
maxRetries: 3,
requestRetryDelay: 0,
Expand All @@ -1109,12 +1109,14 @@ describe('Eureka client', () => {
const client = new Eureka(config);
const requestStub = sinon.stub(request, 'get');
requestStub.onCall(0).yields(null, { statusCode: 500 }, null);
requestStub.onCall(1).yields(null, { statusCode: 200 }, null);
requestStub.onCall(1).yields(null, { statusCode: 400 }, null);
requestStub.onCall(2).yields(null, { statusCode: 200 }, null);
client.eurekaRequest({ uri: '/path' }, (error) => {
expect(error).to.be.null;
expect(requestStub).to.be.calledTwice;
expect(requestStub).to.be.calledThrice;
expect(requestStub.args[0][0]).to.have.property('baseUrl', 'http://serverA');
expect(requestStub.args[1][0]).to.have.property('baseUrl', 'http://serverB');
expect(requestStub.args[2][0]).to.have.property('baseUrl', 'http://serverC');
done();
});
});
Expand Down

0 comments on commit 2fcea81

Please sign in to comment.