when there are timeouts left behind we should spit them out
This commit is contained in:
26
test/fixtures/keepalive.js
vendored
26
test/fixtures/keepalive.js
vendored
@ -1,33 +1,33 @@
|
|||||||
var clock = require('sinon').useFakeTimers();
|
var clock = require('sinon').useFakeTimers();
|
||||||
var elasticsearch = require('../../src/elasticsearch');
|
var Client = require('../../src/elasticsearch').Client;
|
||||||
var _ = require('lodash-node');
|
var _ = require('lodash-node');
|
||||||
var times = require('async').times;
|
var times = require('async').times;
|
||||||
|
|
||||||
var app = require('express')();
|
var app = require('express')();
|
||||||
app.post('/_search', function (req, res) {
|
app.post('/_search', function (req, res) {
|
||||||
res.json(200, { hits: { hits: [] } });
|
res.json(200, { hits: { hits: [] } });
|
||||||
});
|
});
|
||||||
|
|
||||||
var server = require('http').createServer(app);
|
var server = require('http').createServer(app);
|
||||||
server.listen(function () {
|
server.listen(function () {
|
||||||
var es = elasticsearch.Client({
|
var es = new Client({
|
||||||
host: 'http://127.0.0.1:' + server.address().port,
|
host: 'http://127.0.0.1:' + server.address().port,
|
||||||
log: false
|
log: false
|
||||||
});
|
});
|
||||||
|
|
||||||
|
var matchAll = {
|
||||||
|
query: {
|
||||||
|
match_all: {}
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
times(1000, function (i, done) {
|
times(1000, function (i, done) {
|
||||||
es.search({
|
es.search({
|
||||||
body: {
|
body: matchAll
|
||||||
query: {
|
|
||||||
match_all: {}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}, _.partial(done, null)); // ignore errors
|
}, _.partial(done, null)); // ignore errors
|
||||||
clock.tick(10);
|
clock.tick(10);
|
||||||
}, function () {
|
}, function () {
|
||||||
|
|
||||||
server.close();
|
|
||||||
|
|
||||||
var sockets = _(es.transport.connectionPool._conns.dead)
|
var sockets = _(es.transport.connectionPool._conns.dead)
|
||||||
.concat(es.transport.connectionPool._conns.alive)
|
.concat(es.transport.connectionPool._conns.alive)
|
||||||
.transform(function (sockets, conn) {
|
.transform(function (sockets, conn) {
|
||||||
@ -37,14 +37,16 @@ server.listen(function () {
|
|||||||
.flatten()
|
.flatten()
|
||||||
.value();
|
.value();
|
||||||
|
|
||||||
|
server.close();
|
||||||
es.close();
|
es.close();
|
||||||
clock.restore();
|
|
||||||
|
|
||||||
var out = {
|
var out = {
|
||||||
socketCount: sockets.length,
|
socketCount: sockets.length,
|
||||||
remaining: _.where(sockets, { destroyed: true }).length - sockets.length,
|
remaining: _.where(sockets, { destroyed: true }).length - sockets.length,
|
||||||
timeouts: _.size(clock.timeouts)
|
timeouts: _.size(clock.timeouts) && clock.timeouts
|
||||||
};
|
};
|
||||||
|
|
||||||
|
clock.restore();
|
||||||
process.connected ? process.send(out) : console.log(out);
|
process.connected ? process.send(out) : console.log(out);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user