Files
elasticsearch-js/test/fixtures/keepalive.js
2014-03-27 09:49:21 -07:00

38 lines
875 B
JavaScript

var clock = require('sinon').useFakeTimers();
var elasticsearch = require('../../src/elasticsearch');
var _ = require('lodash-node');
var es = elasticsearch.Client({
host: 'localhost:5555',
log: false
});
es.search({
index: '_all',
type: '_all',
body: {
query: {
match_all: {}
}
}
}, function (err, resp) {
var conn = _.union(es.transport.connectionPool._conns.dead, es.transport.connectionPool._conns.alive).pop();
es.close();
if (_.size(clock.timeouts)) {
console.log('Timeouts were left behind');
console.log(clock);
}
clock.restore();
var destroyedSockets = 0;
function countDestroyed(sockets) {
destroyedSockets += _.where(sockets, { destroyed: true}).length;
}
_.each(conn.agent.sockets, countDestroyed);
_.each(conn.agent.freeSockets, countDestroyed);
console.log(destroyedSockets);
});
clock.tick(10);