From 913edeb72804e5774e9ce6242e368893e37f6976 Mon Sep 17 00:00:00 2001 From: Spencer Alger Date: Thu, 27 Mar 2014 18:26:42 -0700 Subject: [PATCH] when there are timeouts left behind we should spit them out --- test/fixtures/keepalive.js | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) diff --git a/test/fixtures/keepalive.js b/test/fixtures/keepalive.js index 0ec9b0710..931925927 100644 --- a/test/fixtures/keepalive.js +++ b/test/fixtures/keepalive.js @@ -1,33 +1,33 @@ var clock = require('sinon').useFakeTimers(); -var elasticsearch = require('../../src/elasticsearch'); +var Client = require('../../src/elasticsearch').Client; var _ = require('lodash-node'); var times = require('async').times; var app = require('express')(); app.post('/_search', function (req, res) { - res.json(200, { hits: { hits: [] } }); + res.json(200, { hits: { hits: [] } }); }); var server = require('http').createServer(app); server.listen(function () { - var es = elasticsearch.Client({ + var es = new Client({ host: 'http://127.0.0.1:' + server.address().port, log: false }); + var matchAll = { + query: { + match_all: {} + } + }; + times(1000, function (i, done) { es.search({ - body: { - query: { - match_all: {} - } - } + body: matchAll }, _.partial(done, null)); // ignore errors clock.tick(10); }, function () { - server.close(); - var sockets = _(es.transport.connectionPool._conns.dead) .concat(es.transport.connectionPool._conns.alive) .transform(function (sockets, conn) { @@ -37,14 +37,16 @@ server.listen(function () { .flatten() .value(); + server.close(); es.close(); - clock.restore(); var out = { socketCount: 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); }); }); \ No newline at end of file