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:
Spencer Alger
2014-03-27 15:02:56 -07:00
parent 1965a597b2
commit 30f2749464

View File

@ -3,15 +3,20 @@ var elasticsearch = require('../../src/elasticsearch');
var _ = require('lodash-node');
var times = require('async').times;
var es = elasticsearch.Client({
host: 'no-a-real-host-for-sure.bike:5555',
log: false
var app = require('express')();
app.post('/_search', function (req, res) {
res.json(200, { hits: { hits: [] } });
});
times(100, function (i, done) {
var server = require('http').createServer(app);
server.listen(function () {
var es = elasticsearch.Client({
host: 'http://127.0.0.1:' + server.address().port,
log: false
});
times(1000, function (i, done) {
es.search({
index: '_all',
type: '_all',
body: {
query: {
match_all: {}
@ -19,7 +24,10 @@ times(100, function (i, done) {
}
}, _.partial(done, null)); // ignore errors
clock.tick(10);
}, function () {
}, function () {
server.close();
var sockets = _(es.transport.connectionPool._conns.dead)
.concat(es.transport.connectionPool._conns.alive)
.transform(function (sockets, conn) {
@ -38,4 +46,5 @@ times(100, function (i, done) {
timeouts: _.size(clock.timeouts)
};
process.connected ? process.send(out) : console.log(out);
});
});