Added behavior test

This commit is contained in:
delvedor
2018-12-05 12:30:44 +01:00
parent 8fd49389f3
commit 18b8c32758
2 changed files with 20 additions and 6 deletions

View File

@ -15,8 +15,9 @@
"index" "index"
], ],
"scripts": { "scripts": {
"test": "npm run lint && npm run test:unit && npm run test:types", "test": "npm run lint && npm run test:unit && npm run test:behavior && npm run test:types",
"test:unit": "tap test/unit/*.test.js -T", "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:integration": "tap test/integration/index.js -T --harmony",
"test:types": "tsc --project ./test/types/tsconfig.json", "test:types": "tsc --project ./test/types/tsconfig.json",
"lint": "standard", "lint": "standard",

View File

@ -5,6 +5,16 @@ const { URL } = require('url')
const { buildCluster } = require('../utils') const { buildCluster } = require('../utils')
const { Client, Connection, Transport, events, errors } = require('../../index') 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 => { test('Should update the connection pool', t => {
t.plan(10) t.plan(10)
@ -41,8 +51,8 @@ test('Should update the connection pool', t => {
} }
t.strictEqual(client.connectionPool.connections.size, 4) t.strictEqual(client.connectionPool.connections.size, 4)
shutdown()
}) })
t.teardown(shutdown)
}) })
}) })
@ -76,8 +86,9 @@ test('Sniff interval', t => {
setTimeout(() => { setTimeout(() => {
t.strictEqual(client.connectionPool.connections.size, 3) t.strictEqual(client.connectionPool.connections.size, 3)
shutdown()
}, 200) }, 200)
t.teardown(shutdown)
}) })
}) })
@ -106,8 +117,9 @@ test('Should not close living connections', t => {
client.connectionPool.connections.size, client.connectionPool.connections.size,
hosts.length hosts.length
) )
shutdown()
}) })
t.teardown(shutdown)
}) })
}) })
@ -134,11 +146,12 @@ test('Sniff on connection fault', t => {
hosts.length hosts.length
) )
t.strictEqual(reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT) t.strictEqual(reason, Transport.sniffReasons.SNIFF_ON_CONNECTION_FAULT)
shutdown()
}) })
client.info((err, result) => { client.info((err, result) => {
t.ok(err instanceof errors.ConnectionError) t.ok(err instanceof errors.ConnectionError)
}) })
t.teardown(shutdown)
}) })
}) })