Skip to content

Commit

Permalink
Correct address status equality check (EnMasseProject#3094)
Browse files Browse the repository at this point in the history
* Fix EnMasseProject#3089: Correct address status equality check

* address review comments
* made same_allocation same implementation symmetric
  • Loading branch information
k-wall authored and Ulf Lilleengen committed Aug 20, 2019
1 parent 6a7a74b commit e0bbae7
Showing 1 changed file with 21 additions and 1 deletion.
22 changes: 21 additions & 1 deletion agent/lib/internal_address_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,11 @@ function ready (addr) {
}

function same_allocation(a, b) {
if (a === b) {
return true;
} else if (a == null || b == null || a.length !== b.length) {
return false;
}
for (var i in a) {
var equal = false;
for (var j in b) {
Expand All @@ -79,6 +84,21 @@ function same_allocation(a, b) {
return true;
}

function same_messages(a, b) {
if (a === b) {
return true;
} else if (a == null || b == null || a.length !== b.length) {
return false;
}

for (var i in a) {
if (!b.includes(a[i])) {
return false;
}
}
return true;
}

function same_address_definition(a, b) {
if (a.address === b.address && a.type === b.type && !same_allocation(a.allocated_to, b.allocated_to)) {
log.info('allocation changed for %s %s: %s <-> %s', a.type, a.address, JSON.stringify(a.allocated_to), JSON.stringify(b.allocated_to));
Expand All @@ -88,7 +108,7 @@ function same_address_definition(a, b) {

function same_address_status(a, b) {
if (a === undefined) return b === undefined;
return a.isReady === b.isReady && a.phase === b.phase && a.message === b.message;
return a.isReady === b.isReady && a.phase === b.phase && same_messages(a.messages, b.messages);
}

function same_address_definition_and_status(a, b) {
Expand Down

0 comments on commit e0bbae7

Please sign in to comment.