use a server that we control to test socket destruction, rather than expecting the OS to kill requests that fail DNS
This commit is contained in:
69
test/fixtures/keepalive.js
vendored
69
test/fixtures/keepalive.js
vendored
@ -3,39 +3,48 @@ var elasticsearch = require('../../src/elasticsearch');
|
|||||||
var _ = require('lodash-node');
|
var _ = require('lodash-node');
|
||||||
var times = require('async').times;
|
var times = require('async').times;
|
||||||
|
|
||||||
var es = elasticsearch.Client({
|
var app = require('express')();
|
||||||
host: 'no-a-real-host-for-sure.bike:5555',
|
app.post('/_search', function (req, res) {
|
||||||
log: false
|
res.json(200, { hits: { hits: [] } });
|
||||||
});
|
});
|
||||||
|
|
||||||
times(100, function (i, done) {
|
var server = require('http').createServer(app);
|
||||||
es.search({
|
server.listen(function () {
|
||||||
index: '_all',
|
var es = elasticsearch.Client({
|
||||||
type: '_all',
|
host: 'http://127.0.0.1:' + server.address().port,
|
||||||
body: {
|
log: false
|
||||||
query: {
|
});
|
||||||
match_all: {}
|
|
||||||
|
times(1000, function (i, done) {
|
||||||
|
es.search({
|
||||||
|
body: {
|
||||||
|
query: {
|
||||||
|
match_all: {}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}, _.partial(done, null)); // ignore errors
|
||||||
}, _.partial(done, null)); // ignore errors
|
clock.tick(10);
|
||||||
clock.tick(10);
|
}, function () {
|
||||||
}, 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();
|
server.close();
|
||||||
clock.restore();
|
|
||||||
|
|
||||||
var out = {
|
var sockets = _(es.transport.connectionPool._conns.dead)
|
||||||
socketCount: sockets.length,
|
.concat(es.transport.connectionPool._conns.alive)
|
||||||
remaining: _.where(sockets, { destroyed: true }).length - sockets.length,
|
.transform(function (sockets, conn) {
|
||||||
timeouts: _.size(clock.timeouts)
|
[].push.apply(sockets, _.values(conn.agent.sockets));
|
||||||
};
|
[].push.apply(sockets, _.values(conn.agent.freeSockets));
|
||||||
process.connected ? process.send(out) : console.log(out);
|
}, [])
|
||||||
|
.flatten()
|
||||||
|
.value();
|
||||||
|
|
||||||
|
es.close();
|
||||||
|
clock.restore();
|
||||||
|
|
||||||
|
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);
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user