From 7fef37cf902ec6b2825ea929eed48cf3734613d0 Mon Sep 17 00:00:00 2001 From: Theodore Cowan Date: Wed, 18 Sep 2019 02:45:47 -0400 Subject: [PATCH] =?UTF-8?q?Fix=20issue;=20node=20roles=20are=20defaulting?= =?UTF-8?q?=20to=20true=20when=20undefined=20(fal=E2=80=A6=20(#967)?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit * 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 --- lib/pool/BaseConnectionPool.js | 6 ++--- test/unit/connection-pool.test.js | 39 +++++++++++++++++++++++++++++++ 2 files changed, 42 insertions(+), 3 deletions(-) diff --git a/lib/pool/BaseConnectionPool.js b/lib/pool/BaseConnectionPool.js index 6241ace5f..811f2a9a8 100644 --- a/lib/pool/BaseConnectionPool.js +++ b/lib/pool/BaseConnectionPool.js @@ -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) }) diff --git a/test/unit/connection-pool.test.js b/test/unit/connection-pool.test.js index 53234d901..8230e6d22 100644 --- a/test/unit/connection-pool.test.js +++ b/test/unit/connection-pool.test.js @@ -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() })