Skip to content

Commit

Permalink
adding tests for DNS error cases and fixing an uncaught exception
Browse files Browse the repository at this point in the history
  • Loading branch information
jquatier committed May 5, 2016
1 parent f190333 commit ff5233c
Show file tree
Hide file tree
Showing 2 changed files with 48 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/EurekaClient.js
Original file line number Diff line number Diff line change
Expand Up @@ -467,7 +467,7 @@ export default class Eureka extends EventEmitter {
}
dns.resolveTxt(`txt.${ec2Region}.${host}`, (err, addresses) => {
if (err) {
callback(new Error(
return callback(new Error(
`Error resolving eureka server list for region [${ec2Region}] using DNS: [${err}]`
));
}
Expand Down
47 changes: 47 additions & 0 deletions test/EurekaClient.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -836,5 +836,52 @@ describe('Eureka client', () => {
);
expect(locateCb).to.have.been.calledWithMatch(null, '1.2.3.4');
});

it('should return error when initial DNS lookup fails', () => {
config = makeConfig({
eureka: { host: 'eureka.mydomain.com', port: 9999, ec2Region: 'my-region' },
});
client = new Eureka(config);

const locateCb = sinon.spy();
const resolveStub = sinon.stub(dns, 'resolveTxt');
resolveStub.onCall(0).yields(new Error('dns error'), null);

function shouldNotThrow() {
client.locateEurekaHostUsingDns(locateCb);
}

expect(shouldNotThrow).to.not.throw();
expect(dns.resolveTxt).to.have.been.calledWithMatch('txt.my-region.eureka.mydomain.com');
expect(locateCb).to.have.been.calledWithMatch({
message: 'Error resolving eureka server ' +
'list for region [my-region] using DNS: [Error: dns error]',
});
});

it('should return error when DNS lookup fails for an individual Eureka server', () => {
config = makeConfig({
eureka: { host: 'eureka.mydomain.com', port: 9999, ec2Region: 'my-region' },
});
client = new Eureka(config);

const locateCb = sinon.spy();
const resolveStub = sinon.stub(dns, 'resolveTxt');
resolveStub.onCall(0).yields(null, [eurekaHosts]);
resolveStub.onCall(1).yields(new Error('dns error'), null);

function shouldNotThrow() {
client.locateEurekaHostUsingDns(locateCb);
}

expect(shouldNotThrow).to.not.throw();
expect(dns.resolveTxt).to.have.been.calledWithMatch('txt.my-region.eureka.mydomain.com');
expect(dns.resolveTxt).to.have.been.calledWith(
sinon.match(value => eurekaHosts.indexOf(value))
);
expect(locateCb).to.have.been.calledWithMatch({
message: 'Error locating eureka server using DNS: [Error: dns error]',
});
});
});
});

0 comments on commit ff5233c

Please sign in to comment.