From 18b8c3275861e8c3183870472946374442a8e5a4 Mon Sep 17 00:00:00 2001 From: delvedor Date: Wed, 5 Dec 2018 12:30:44 +0100 Subject: [PATCH] Added behavior test --- package.json | 5 +++-- test/{unit => behavior}/sniff.test.js | 21 +++++++++++++++++---- 2 files changed, 20 insertions(+), 6 deletions(-) rename test/{unit => behavior}/sniff.test.js (88%) diff --git a/package.json b/package.json index 49fff7e44..4d4b9c666 100644 --- a/package.json +++ b/package.json @@ -15,8 +15,9 @@ "index" ], "scripts": { - "test": "npm run lint && npm run test:unit && npm run test:types", - "test:unit": "tap test/unit/*.test.js -T", + "test": "npm run lint && npm run test:unit && npm run test:behavior && npm run test:types", + "test:unit": "tap test/unit/*.test.js -J -T", + "test:behavior": "tap test/behavior/*.test.js -J -T", "test:integration": "tap test/integration/index.js -T --harmony", "test:types": "tsc --project ./test/types/tsconfig.json", "lint": "standard", diff --git a/test/unit/sniff.test.js b/test/behavior/sniff.test.js similarity index 88% rename from test/unit/sniff.test.js rename to test/behavior/sniff.test.js index 14e818b57..97e184126 100644 --- a/test/unit/sniff.test.js +++ b/test/behavior/sniff.test.js @@ -5,6 +5,16 @@ const { URL } = require('url') const { buildCluster } = require('../utils') const { Client, Connection, Transport, events, errors } = require('../../index') +/** + * The aim of this test is to verify how the sniffer behaves + * in a multi node situation. + * The `buildCluster` utility can boot an arbitrary number + * of nodes, that you can kill or spawn at your will. + * The sniffer component can be tested with its callback + * or by using the `sniff` event (to handle automatically + * triggered sniff). + */ + test('Should update the connection pool', t => { t.plan(10) @@ -41,8 +51,8 @@ test('Should update the connection pool', t => { } t.strictEqual(client.connectionPool.connections.size, 4) - shutdown() }) + t.teardown(shutdown) }) }) @@ -76,8 +86,9 @@ test('Sniff interval', t => { setTimeout(() => { t.strictEqual(client.connectionPool.connections.size, 3) - shutdown() }, 200) + + t.teardown(shutdown) }) }) @@ -106,8 +117,9 @@ test('Should not close living connections', t => { client.connectionPool.connections.size, hosts.length ) - shutdown() }) + + t.teardown(shutdown) }) }) @@ -134,11 +146,12 @@ test('Sniff on connection fault', t => { hosts.length ) t.strictEqual(reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT) - shutdown() }) client.info((err, result) => { t.ok(err instanceof errors.ConnectionError) }) + + t.teardown(shutdown) }) })