attempting to diagnos random issues with the client.close() test

This commit is contained in:
Spencer Alger
2014-02-10 13:34:02 -07:00
parent e8067df259
commit 257d596207
3 changed files with 21 additions and 6 deletions

View File

@ -57,17 +57,21 @@ _.inherits(HttpConnector, ConnectionAbstract);
HttpConnector.prototype.onStatusSet = _.handler(function (status) { HttpConnector.prototype.onStatusSet = _.handler(function (status) {
if (status === 'closed') { if (status === 'closed') {
this.agent.minSockets = this.agent.maxSockets = 0; var agent = this.agent;
agent.minSockets = agent.maxSockets = 0;
agent.requests = {};
_.each(this.agent.sockets, function (sockets) { _.each(agent.sockets, function (sockets, group) {
_.each(sockets, function (s) { _.each(sockets, function (s) {
s.destroy(); s && agent.removeSocket(s, group);
s && s.destroy();
}); });
}); });
_.each(this.agent.freeSockets, function (sockets) { _.each(agent.freeSockets, function (sockets, group) {
_.each(sockets, function (s) { _.each(sockets, function (s) {
s.destroy(); s && agent.removeSocket(s, group);
s && s.destroy();
}); });
}); });
} }

View File

@ -1,5 +1,7 @@
var elasticsearch = require('../../src/elasticsearch'); var elasticsearch = require('../../src/elasticsearch');
var _ = require('lodash'); var _ = require('lodash');
var clock = require('sinon').useFakeTimers();
var es = elasticsearch.Client({ var es = elasticsearch.Client({
host: 'localhost:5555', host: 'localhost:5555',
log: false log: false
@ -16,6 +18,12 @@ es.search({
}, function (err, resp) { }, function (err, resp) {
var conn = _.union(es.transport.connectionPool._conns.dead, es.transport.connectionPool._conns.alive).pop(); var conn = _.union(es.transport.connectionPool._conns.dead, es.transport.connectionPool._conns.alive).pop();
es.close(); es.close();
if (_.size(clock.timeouts)) {
console.log('Timeouts were left behind');
console.log(clock);
}
var destroyedSockets = 0; var destroyedSockets = 0;
function countDestroyed(sockets) { function countDestroyed(sockets) {
destroyedSockets += _.where(sockets, { destroyed: true}).length; destroyedSockets += _.where(sockets, { destroyed: true}).length;
@ -23,4 +31,6 @@ es.search({
_.each(conn.agent.sockets, countDestroyed); _.each(conn.agent.sockets, countDestroyed);
_.each(conn.agent.freeSockets, countDestroyed); _.each(conn.agent.freeSockets, countDestroyed);
console.log(destroyedSockets); console.log(destroyedSockets);
}); });
clock.tick(1);

View File

@ -371,6 +371,7 @@ describe('Http Connector', function () {
describe('Connection cleanup', function () { describe('Connection cleanup', function () {
it('destroys any connections created', function (done) { it('destroys any connections created', function (done) {
this.timeout(4000);
var cp = require('child_process'); var cp = require('child_process');
var path = require('path'); var path = require('path');
var es = require('event-stream'); var es = require('event-stream');