From bcf895294b11f484e0f417cd2c8d9f30bc83b66a Mon Sep 17 00:00:00 2001 From: delvedor Date: Tue, 19 Feb 2019 08:31:09 +0100 Subject: [PATCH] Updated test --- test/integration/test-runner.js | 14 +++++++++++ test/unit/client.test.js | 27 +++++++++++++++++++++ test/unit/connection-pool.test.js | 40 ++++++++++++++++++++++++++----- 3 files changed, 75 insertions(+), 6 deletions(-) diff --git a/test/integration/test-runner.js b/test/integration/test-runner.js index 1c7fc4757..2f8fa0b97 100644 --- a/test/integration/test-runner.js +++ b/test/integration/test-runner.js @@ -53,6 +53,20 @@ TestRunner.prototype.cleanup = function (q, done) { }) }) + q.add((q, done) => { + this.client.snapshot.delete({ repository: '*', snapshot: '*' }, { ignore: 404 }, err => { + this.tap.error(err, 'should not error:snapshot.delete') + done() + }) + }) + + q.add((q, done) => { + this.client.snapshot.deleteRepository({ repository: '*' }, { ignore: 404 }, err => { + this.tap.error(err, 'should not error:snapshot.deleteRepository') + done() + }) + }) + done() } diff --git a/test/unit/client.test.js b/test/unit/client.test.js index ff895a740..45f928ece 100644 --- a/test/unit/client.test.js +++ b/test/unit/client.test.js @@ -496,3 +496,30 @@ test('Extend client APIs', t => { t.end() }) + +test('Elastic cloud config', t => { + t.plan(1) + const client = new Client({ + cloud: { + // 'localhost$abcd$efgh' + id: 'name:bG9jYWxob3N0JGFiY2QkZWZnaA==', + username: 'elastic', + password: 'changeme' + } + }) + + const pool = client.connectionPool + t.match(pool.connections.get('https://abcd.localhost/'), { + url: new URL('https://elastic:changeme@abcd.localhost'), + id: 'https://abcd.localhost/', + ssl: null, + deadCount: 0, + resurrectTimeout: 0, + roles: { + master: true, + data: true, + ingest: true, + ml: false + } + }) +}) diff --git a/test/unit/connection-pool.test.js b/test/unit/connection-pool.test.js index 734877d1f..0969e21a0 100644 --- a/test/unit/connection-pool.test.js +++ b/test/unit/connection-pool.test.js @@ -47,7 +47,7 @@ test('API', t => { }) t.test('markDead', t => { - const pool = new ConnectionPool({ Connection }) + const pool = new ConnectionPool({ Connection, sniffEnabled: true }) const href = 'http://localhost:9200/' var connection = pool.addConnection(href) pool.markDead(connection) @@ -73,7 +73,7 @@ test('API', t => { }) t.test('markAlive', t => { - const pool = new ConnectionPool({ Connection }) + const pool = new ConnectionPool({ Connection, sniffEnabled: true }) const href = 'http://localhost:9200/' var connection = pool.addConnection(href) pool.markDead(connection) @@ -92,7 +92,8 @@ test('API', t => { const pool = new ConnectionPool({ resurrectStrategy: 'ping', pingTimeout: 3000, - Connection: MockConnection + Connection: MockConnection, + sniffEnabled: true }) const href = 'http://localhost:9200/' var connection = pool.addConnection(href) @@ -112,7 +113,8 @@ test('API', t => { const pool = new ConnectionPool({ resurrectStrategy: 'ping', pingTimeout: 3000, - Connection: MockConnectionTimeout + Connection: MockConnectionTimeout, + sniffEnabled: true }) const href = 'http://localhost:9200/' var connection = pool.addConnection(href) @@ -134,7 +136,8 @@ test('API', t => { t.test('optimistic strategy', t => { const pool = new ConnectionPool({ resurrectStrategy: 'optimistic', - Connection + Connection, + sniffEnabled: true }) const href = 'http://localhost:9200/' var connection = pool.addConnection(href) @@ -153,7 +156,8 @@ test('API', t => { t.test('none strategy', t => { const pool = new ConnectionPool({ resurrectStrategy: 'none', - Connection + Connection, + sniffEnabled: true }) const href = 'http://localhost:9200/' var connection = pool.addConnection(href) @@ -567,3 +571,27 @@ test('Node filter', t => { t.end() }) + +test('Single node behavior', t => { + t.test('sniffing disabled (markDead and markAlive should be noop)', t => { + t.plan(2) + const pool = new ConnectionPool({ Connection, sniffEnabled: false }) + const conn = pool.addConnection('http://localhost:9200/') + pool.markDead(conn) + t.strictEqual(pool.dead.length, 0) + pool.markAlive(conn) + t.strictEqual(pool.dead.length, 0) + }) + + t.test('sniffing enabled (markDead and markAlive should work)', t => { + t.plan(2) + const pool = new ConnectionPool({ Connection, sniffEnabled: true }) + const conn = pool.addConnection('http://localhost:9200/') + pool.markDead(conn) + t.strictEqual(pool.dead.length, 1) + pool.markAlive(conn) + t.strictEqual(pool.dead.length, 0) + }) + + t.end() +})