updated the keepalive test so that it uses IPC instead of output parsing.
This commit is contained in:
55
test/fixtures/keepalive.js
vendored
55
test/fixtures/keepalive.js
vendored
@ -1,38 +1,41 @@
|
||||
var clock = require('sinon').useFakeTimers();
|
||||
var elasticsearch = require('../../src/elasticsearch');
|
||||
var _ = require('lodash-node');
|
||||
var times = require('async').times;
|
||||
|
||||
var es = elasticsearch.Client({
|
||||
host: 'localhost:5555',
|
||||
host: 'no-a-real-host-for-sure.bike:5555',
|
||||
log: false
|
||||
});
|
||||
|
||||
es.search({
|
||||
index: '_all',
|
||||
type: '_all',
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
times(100, function (i, done) {
|
||||
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();
|
||||
}, _.partial(done, null)); // ignore errors
|
||||
clock.tick(10);
|
||||
}, function () {
|
||||
var sockets = _(es.transport.connectionPool._conns.dead)
|
||||
.concat(es.transport.connectionPool._conns.alive)
|
||||
.transform(function (sockets, conn) {
|
||||
[].push.apply(sockets, _.values(conn.agent.sockets));
|
||||
[].push.apply(sockets, _.values(conn.agent.freeSockets));
|
||||
}, [])
|
||||
.flatten()
|
||||
.value();
|
||||
|
||||
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);
|
||||
var out = {
|
||||
socketCount: sockets.length,
|
||||
remaining: _.where(sockets, { destroyed: true }).length - sockets.length,
|
||||
timeouts: _.size(clock.timeouts)
|
||||
};
|
||||
process.connected ? process.send(out) : console.log(out);
|
||||
});
|
||||
@ -376,18 +376,16 @@ describe('Http Connector', function () {
|
||||
var path = require('path');
|
||||
var es = require('event-stream');
|
||||
|
||||
var proc = cp.spawn('node', [path.join(__dirname, '../../fixtures/keepalive.js')], {
|
||||
silent: true
|
||||
});
|
||||
var proc = cp.fork(path.join(__dirname, '../../fixtures/keepalive.js'));
|
||||
|
||||
proc.on('message', function (output) {
|
||||
proc.kill();
|
||||
|
||||
expect(output).to.have.property('remaining', 0);
|
||||
expect(output).to.have.property('timeouts', 0);
|
||||
|
||||
es.merge(
|
||||
proc.stdout,
|
||||
proc.stderr
|
||||
).pipe(es.wait(function (err, output) {
|
||||
expect(err).to.eql(null);
|
||||
expect(parseInt(output.trim(), 10) <= 1).to.be.ok();
|
||||
done();
|
||||
}));
|
||||
});
|
||||
});
|
||||
|
||||
it('properly removes all elements from the socket', function () {
|
||||
|
||||
Reference in New Issue
Block a user