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 clock = require('sinon').useFakeTimers();
|
||||||
var elasticsearch = require('../../src/elasticsearch');
|
var elasticsearch = require('../../src/elasticsearch');
|
||||||
var _ = require('lodash-node');
|
var _ = require('lodash-node');
|
||||||
|
var times = require('async').times;
|
||||||
|
|
||||||
var es = elasticsearch.Client({
|
var es = elasticsearch.Client({
|
||||||
host: 'localhost:5555',
|
host: 'no-a-real-host-for-sure.bike:5555',
|
||||||
log: false
|
log: false
|
||||||
});
|
});
|
||||||
|
|
||||||
es.search({
|
times(100, function (i, done) {
|
||||||
index: '_all',
|
es.search({
|
||||||
type: '_all',
|
index: '_all',
|
||||||
body: {
|
type: '_all',
|
||||||
query: {
|
body: {
|
||||||
match_all: {}
|
query: {
|
||||||
|
match_all: {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}, _.partial(done, null)); // ignore errors
|
||||||
}, function (err, resp) {
|
clock.tick(10);
|
||||||
var conn = _.union(es.transport.connectionPool._conns.dead, es.transport.connectionPool._conns.alive).pop();
|
}, 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();
|
es.close();
|
||||||
|
|
||||||
if (_.size(clock.timeouts)) {
|
|
||||||
console.log('Timeouts were left behind');
|
|
||||||
console.log(clock);
|
|
||||||
}
|
|
||||||
|
|
||||||
clock.restore();
|
clock.restore();
|
||||||
|
|
||||||
var destroyedSockets = 0;
|
var out = {
|
||||||
function countDestroyed(sockets) {
|
socketCount: sockets.length,
|
||||||
destroyedSockets += _.where(sockets, { destroyed: true}).length;
|
remaining: _.where(sockets, { destroyed: true }).length - sockets.length,
|
||||||
}
|
timeouts: _.size(clock.timeouts)
|
||||||
_.each(conn.agent.sockets, countDestroyed);
|
};
|
||||||
_.each(conn.agent.freeSockets, countDestroyed);
|
process.connected ? process.send(out) : console.log(out);
|
||||||
console.log(destroyedSockets);
|
});
|
||||||
});
|
|
||||||
|
|
||||||
clock.tick(10);
|
|
||||||
@ -376,18 +376,16 @@ describe('Http Connector', function () {
|
|||||||
var path = require('path');
|
var path = require('path');
|
||||||
var es = require('event-stream');
|
var es = require('event-stream');
|
||||||
|
|
||||||
var proc = cp.spawn('node', [path.join(__dirname, '../../fixtures/keepalive.js')], {
|
var proc = cp.fork(path.join(__dirname, '../../fixtures/keepalive.js'));
|
||||||
silent: true
|
|
||||||
});
|
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();
|
done();
|
||||||
}));
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
it('properly removes all elements from the socket', function () {
|
it('properly removes all elements from the socket', function () {
|
||||||
|
|||||||
Reference in New Issue
Block a user