test fixes...
This commit is contained in:
38
test/fixtures/keepalive.js
vendored
38
test/fixtures/keepalive.js
vendored
@ -3,33 +3,24 @@ 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: [] } });
|
||||
});
|
||||
|
||||
var server = require('http').createServer(app);
|
||||
server.listen(function () {
|
||||
process.once('message', function (port) {
|
||||
var es = new Client({
|
||||
host: 'http://127.0.0.1:' + server.address().port,
|
||||
host: 'http://127.0.0.1:' + port,
|
||||
log: false
|
||||
});
|
||||
|
||||
var matchAll = {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
};
|
||||
|
||||
times(1000, function (i, done) {
|
||||
times(1000, function (n, done) {
|
||||
es.search({
|
||||
body: matchAll
|
||||
}, _.partial(done, null)); // ignore errors
|
||||
body: {
|
||||
query: {
|
||||
match_all: {}
|
||||
}
|
||||
}
|
||||
}, done);
|
||||
clock.tick(10);
|
||||
}, function () {
|
||||
|
||||
var sockets = _(es.transport.connectionPool._conns.dead)
|
||||
.concat(es.transport.connectionPool._conns.alive)
|
||||
}, function (err) {
|
||||
var conns = es.transport.connectionPool._conns;
|
||||
var sockets = _([].concat(conns.dead, conns.alive))
|
||||
.transform(function (sockets, conn) {
|
||||
[].push.apply(sockets, _.values(conn.agent.sockets));
|
||||
[].push.apply(sockets, _.values(conn.agent.freeSockets));
|
||||
@ -37,13 +28,12 @@ server.listen(function () {
|
||||
.flatten()
|
||||
.value();
|
||||
|
||||
server.close();
|
||||
es.close();
|
||||
|
||||
var out = {
|
||||
socketCount: sockets.length,
|
||||
socketCount: err || sockets.length,
|
||||
remaining: _.where(sockets, { destroyed: true }).length - sockets.length,
|
||||
timeouts: _.size(clock.timeouts) && clock.timeouts
|
||||
timeouts: _.size(clock.timeouts) && _.pluck(clock.timeouts, 'func').map(String)
|
||||
};
|
||||
|
||||
clock.restore();
|
||||
|
||||
16
test/fixtures/keepalive_server.js
vendored
Normal file
16
test/fixtures/keepalive_server.js
vendored
Normal file
@ -0,0 +1,16 @@
|
||||
// fake es server for the keepalive test script
|
||||
|
||||
// Node 0.9.25 uses timeouts for outgoing messages
|
||||
// which prevent sinon from being able to ensure
|
||||
// timeouts aren't being left behind
|
||||
|
||||
var express = require('express');
|
||||
var app = express().post('/_search', function (req, res) {
|
||||
res.json(200, { hits: { hits: [] } });
|
||||
});
|
||||
|
||||
var server = require('http').createServer(app);
|
||||
server.listen(function () {
|
||||
var port = server.address().port;
|
||||
process.connected ? process.send(port) : console.log(port);
|
||||
});
|
||||
@ -128,28 +128,27 @@ function YamlDoc(doc, file) {
|
||||
action.bound = _.bind(method, self, action.args);
|
||||
|
||||
// create a function that can be passed to mocha or async
|
||||
action.testable = function (done) {
|
||||
action.testable = function (_cb) {
|
||||
function done(err) {
|
||||
process.nextTick(function () {
|
||||
if (err) {
|
||||
err.message += ' in ' + action.name;
|
||||
}
|
||||
_cb(err);
|
||||
});
|
||||
}
|
||||
|
||||
if (self.skipping || self.file.skipping) {
|
||||
return done();
|
||||
}
|
||||
if (method.length > 1) {
|
||||
action.bound(function (err) {
|
||||
if (err) {
|
||||
err.message += ' in ' + action.name;
|
||||
}
|
||||
process.nextTick(function () {
|
||||
done(err);
|
||||
});
|
||||
});
|
||||
action.bound(done);
|
||||
} else {
|
||||
try {
|
||||
action.bound();
|
||||
process.nextTick(done);
|
||||
} catch (err) {
|
||||
err.message += ' in ' + action.name;
|
||||
process.nextTick(function () {
|
||||
done(err);
|
||||
});
|
||||
done(err);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
@ -371,19 +371,35 @@ describe('Http Connector', function () {
|
||||
|
||||
describe('Connection cleanup', function () {
|
||||
it('destroys any connections created', function (done) {
|
||||
this.timeout(10000);
|
||||
this.timeout(null);
|
||||
var cp = require('child_process');
|
||||
var path = require('path');
|
||||
var es = require('event-stream');
|
||||
var fixtures = path.join(__dirname, '../../fixtures/');
|
||||
var timeout; // start the timeout once we hear back from the client
|
||||
|
||||
var proc = cp.fork(path.join(__dirname, '../../fixtures/keepalive.js'));
|
||||
var server = cp.fork(fixtures + 'keepalive_server.js');
|
||||
var client = cp.fork(fixtures + 'keepalive.js');
|
||||
|
||||
proc.on('message', function (output) {
|
||||
proc.kill();
|
||||
server.on('message', function (port) {
|
||||
client.send(port);
|
||||
});
|
||||
|
||||
client.on('message', function (output) {
|
||||
expect(output).to.have.property('remaining', 0);
|
||||
expect(output).to.have.property('timeouts', 0);
|
||||
server.kill('SIGKILL');
|
||||
if (client.connected) {
|
||||
client.disconnect();
|
||||
}
|
||||
|
||||
timeout = setTimeout(function () {
|
||||
client.removeListener('exit');
|
||||
done(new Error('process should have closed by now'));
|
||||
}, 2000);
|
||||
});
|
||||
|
||||
client.on('exit', function () {
|
||||
clearTimeout(timeout);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user