Updated behavior test
This commit is contained in:
@ -16,8 +16,8 @@
|
|||||||
],
|
],
|
||||||
"scripts": {
|
"scripts": {
|
||||||
"test": "npm run lint && npm run test:unit && npm run test:behavior && 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 -J -T",
|
"test:unit": "tap test/unit/*.test.js -J -t 300",
|
||||||
"test:behavior": "tap test/behavior/*.test.js -J -T",
|
"test:behavior": "tap test/behavior/*.test.js -J -t 300",
|
||||||
"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",
|
||||||
|
|||||||
@ -92,6 +92,29 @@ test('Sniff interval', t => {
|
|||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
|
||||||
|
test('Sniff on start', t => {
|
||||||
|
t.plan(4)
|
||||||
|
|
||||||
|
buildCluster(({ nodes, shutdown, kill }) => {
|
||||||
|
const client = new Client({
|
||||||
|
node: nodes[Object.keys(nodes)[0]].url,
|
||||||
|
sniffOnStart: true
|
||||||
|
})
|
||||||
|
|
||||||
|
client.on(events.SNIFF, (err, { hosts, reason }) => {
|
||||||
|
t.error(err)
|
||||||
|
t.strictEqual(
|
||||||
|
client.connectionPool.connections.size,
|
||||||
|
hosts.length
|
||||||
|
)
|
||||||
|
t.strictEqual(reason, Transport.sniffReasons.SNIFF_ON_START)
|
||||||
|
})
|
||||||
|
|
||||||
|
t.strictEqual(client.connectionPool.connections.size, 1)
|
||||||
|
t.teardown(shutdown)
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
test('Should not close living connections', t => {
|
test('Should not close living connections', t => {
|
||||||
t.plan(3)
|
t.plan(3)
|
||||||
|
|
||||||
@ -126,18 +149,29 @@ test('Should not close living connections', t => {
|
|||||||
test('Sniff on connection fault', t => {
|
test('Sniff on connection fault', t => {
|
||||||
t.plan(5)
|
t.plan(5)
|
||||||
|
|
||||||
buildCluster(({ nodes, shutdown }) => {
|
buildCluster(({ nodes, shutdown, kill }) => {
|
||||||
|
class MyConnection extends Connection {
|
||||||
|
request (params, callback) {
|
||||||
|
if (this.id === 'http://localhost:9200/') {
|
||||||
|
callback(new Error('kaboom'), null)
|
||||||
|
return {}
|
||||||
|
} else {
|
||||||
|
return super.request(params, callback)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
const client = new Client({
|
const client = new Client({
|
||||||
nodes: [
|
nodes: [
|
||||||
// TODO: this url may cause a flaky test
|
|
||||||
'http://localhost:9200',
|
'http://localhost:9200',
|
||||||
nodes[Object.keys(nodes)[0]].url
|
nodes[Object.keys(nodes)[0]].url
|
||||||
],
|
],
|
||||||
maxRetries: 0,
|
maxRetries: 0,
|
||||||
sniffOnConnectionFault: true
|
sniffOnConnectionFault: true,
|
||||||
|
Connection: MyConnection
|
||||||
})
|
})
|
||||||
t.strictEqual(client.connectionPool.connections.size, 2)
|
|
||||||
|
|
||||||
|
t.strictEqual(client.connectionPool.connections.size, 2)
|
||||||
// this event will be triggered by the connection fault
|
// this event will be triggered by the connection fault
|
||||||
client.on(events.SNIFF, (err, { hosts, reason }) => {
|
client.on(events.SNIFF, (err, { hosts, reason }) => {
|
||||||
t.error(err)
|
t.error(err)
|
||||||
|
|||||||
Reference in New Issue
Block a user