Skip to content

Commit

Permalink
Fix issue; node roles are defaulting to true when undefined (fal… (#967)
Browse files Browse the repository at this point in the history
* Fix issue; nodeFilter was unable to filter because master, data, and ingest role were true if even they were false on the node.

* Test nodesToHost of BaseConnectionPool correctly maps node roles
  • Loading branch information
deuscapturus authored and delvedor committed Sep 18, 2019
1 parent 90ad163 commit 7fef37c
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 3 deletions.
6 changes: 3 additions & 3 deletions lib/pool/BaseConnectionPool.js
Original file line number Diff line number Diff line change
Expand Up @@ -212,9 +212,9 @@ class BaseConnectionPool {
url: new URL(address),
id: ids[i],
roles: Object.assign({
[Connection.roles.MASTER]: true,
[Connection.roles.DATA]: true,
[Connection.roles.INGEST]: true,
[Connection.roles.MASTER]: false,
[Connection.roles.DATA]: false,
[Connection.roles.INGEST]: false,
[Connection.roles.ML]: false
}, roles)
})
Expand Down
39 changes: 39 additions & 0 deletions test/unit/connection-pool.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -474,6 +474,45 @@ test('API', t => {
t.end()
})

t.test('Should map roles', t => {
const pool = new ConnectionPool({ Connection })
const nodes = {
a1: {
http: {
publish_address: 'example.com:9200'
},
roles: ['master', 'data', 'ingest', 'ml']
},
a2: {
http: {
publish_address: 'example.com:9201'
},
roles: []
}
}
t.same(pool.nodesToHost(nodes, 'http:'), [{
url: new URL('http://example.com:9200'),
id: 'a1',
roles: {
master: true,
data: true,
ingest: true,
ml: true
}
}, {
url: new URL('http://example.com:9201'),
id: 'a2',
roles: {
master: false,
data: false,
ingest: false,
ml: false
}
}])

t.end()
})

t.end()
})

Expand Down

0 comments on commit 7fef37c

Please sign in to comment.