From 230973fdc4fca2d4aef25a3fe7f9943eada50a77 Mon Sep 17 00:00:00 2001 From: Kiran Manda Date: Tue, 30 Oct 2018 08:33:00 -0700 Subject: [PATCH] The modifyInstance() function is returning back to the caller when the the instance is not in UP status. So the cache is never updated to the OUT_OF_SERVICE status. This should fix that problem. (#148) --- .gitignore | 3 +++ package.json | 2 +- src/EurekaClient.js | 1 - test/EurekaClient.test.js | 21 +++++++++++++++++++++ 4 files changed, 25 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 096bec9..79dc888 100644 --- a/.gitignore +++ b/.gitignore @@ -29,3 +29,6 @@ node_modules lib/ .DS_Store + +#IDE +.idea diff --git a/package.json b/package.json index 30d693c..f9b80d0 100644 --- a/package.json +++ b/package.json @@ -1,6 +1,6 @@ { "name": "eureka-js-client", - "version": "4.4.1", + "version": "4.4.2", "description": "A JavaScript implementation the Netflix OSS service registry, Eureka.", "main": "lib/index.js", "scripts": { diff --git a/src/EurekaClient.js b/src/EurekaClient.js index 2208fef..91f8860 100644 --- a/src/EurekaClient.js +++ b/src/EurekaClient.js @@ -484,7 +484,6 @@ export default class Eureka extends EventEmitter { } modifyInstance(cache, instance) { - if (!this.validateInstance(instance)) return; const vipAddresses = this.splitVipAddress(instance.vipAddress); const appName = instance.app.toUpperCase(); vipAddresses.forEach((vipAddress) => { diff --git a/test/EurekaClient.test.js b/test/EurekaClient.test.js index f1e0d0d..99a943b 100644 --- a/test/EurekaClient.test.js +++ b/test/EurekaClient.test.js @@ -1178,6 +1178,27 @@ describe('Eureka client', () => { expect(client.cache.app.THEAPP[0]).to.have.property('newProp'); }); + it('should modify instances even when status is not UP', () => { + const appDelta = [ + { + instance: [ + { hostName: '127.0.0.1', port: { $: 1000 }, app: 'THEAPP', vipAddress: 'thevip', status: 'DOWN', actionType: 'MODIFIED', newProp: 'foo' }, + ], + }, + ]; + const original = { hostName: '127.0.0.1', port: { $: 1000 }, app: 'THEAPP', vipAddress: 'thevip', status: 'UP', actionType: 'MODIFIED' }; + client.cache = { + app: { THEAPP: [original] }, + vip: { thevip: [original] }, + }; + + client.handleDelta(client.cache, appDelta); + expect(client.cache.vip.thevip).to.have.length(1); + expect(client.cache.app.THEAPP).to.have.length(1); + expect(client.cache.vip.thevip[0]).to.have.property('newProp'); + expect(client.cache.app.THEAPP[0]).to.have.property('newProp'); + }); + it('should add if instance doesnt exist when modifying', () => { const appDelta = [ {