Summary of Changes:

- moved es install/start/stop logic into a seperate script
  - `grunt test` now runs the integration tests once for each version of ES we support
  - grunt can now install and run elasticearch (using grunt-run, pure js solution coming later)
  - included seperate es.sh script specifically for starting or stopping elasticsearch
  - url aliases, api, yaml_suite/index.js, and yaml_tests.json, are all now duplicated for 0_90 support
  - the client now accepts an apiVersion argument (undocumented) which defaults to 'master' but can be '0.90'
  - The yaml test runner will now check the name of the ES instance it is connecting to, preventing accidental wiping of ES
This commit is contained in:
Spencer Alger
2014-01-14 23:10:12 -07:00
parent 37ce4e440c
commit 18e134d0a6
30 changed files with 23318 additions and 560 deletions

View File

@ -8,7 +8,6 @@ if (BROWSER) {
var es = require('../../../src/elasticsearch');
}
var argv = require('./argv');
var server = require('./server');
var fs = require('relative-fs').relativeTo(require('path').join(__dirname, '../../../'));
var _ = require('../../../src/lib/utils');
@ -18,11 +17,8 @@ var client = null;
// when set to a boolean, hold the test of a ping
var externalExists;
// a reference to a personal instance of ES Server
var esServer = null;
module.exports = {
create: function create(cb) {
create: function create(branch, cb) {
// create a client and ping the server for up to 15 seconds
doCreateClient({
logConfig: null
@ -31,14 +27,17 @@ module.exports = {
var timeout = 500;
(function ping() {
client.ping({
client.info({
maxRetries: 0,
requestTimeout: 100
}, function (err) {
}, function (err, resp) {
if (err && --attemptsRemaining) {
setTimeout(ping, timeout);
} else if (err) {
cb(new Error('unable to establish contact with ES'));
} else if (resp.name !== 'elasticsearch_js_test_runner') {
console.log(resp);
cb(new Error('Almosted wiped out another es node. Shut-down all instances of ES and try again.'));
} else {
// create a new client
doCreateClient(function () {
@ -79,10 +78,11 @@ module.exports = {
}
client = new es.Client({
apiVersion: branch,
hosts: [
{
host: esServer ? esServer.__hostname : argv.host,
port: esServer ? esServer.__port : argv.port
host: argv.host,
port: argv.port
}
],
log: logConfig

View File

@ -1,33 +1 @@
var path = require('path');
var async = require('async');
var jsYaml = require('js-yaml');
var YamlFile = require('./yaml_file');
var _ = require('../../../src/lib/utils');
var es = require('../../../src/elasticsearch');
var clientManager = require('./client_manager');
var argv = require('./argv');
var testDir = path.resolve(__dirname, './tests');
describe('integration', function () {
this.timeout(30000);
// before running any tests...
before(function (done) {
// start our personal ES Server
this.timeout(null);
clientManager.create(done);
});
before(function (done) {
// make sure ES is empty
clientManager.get().indices.delete({
index: '*',
ignore: 404
}, done);
});
var files = _.map(require('./yaml_tests.json'), function (docs, filename) {
return new YamlFile(filename, docs);
});
});
require('./run')('master');

View File

@ -0,0 +1 @@
require('./run')('0.90');

View File

@ -0,0 +1,35 @@
module.exports = function (branch) {
var path = require('path');
var async = require('async');
var jsYaml = require('js-yaml');
var YamlFile = require('./yaml_file');
var _ = require('../../../src/lib/utils');
var es = require('../../../src/elasticsearch');
var clientManager = require('./client_manager');
var argv = require('./argv');
var branchSuffix = branch === 'master' ? '' : '_' + _.snakeCase(branch);
describe('integration', function () {
this.timeout(30000);
// before running any tests...
before(function (done) {
// start our personal ES Server
this.timeout(null);
clientManager.create(branch, done);
});
before(function (done) {
// make sure ES is empty
clientManager.get().indices.delete({
index: '*',
ignore: 404
}, done);
});
var files = _.map(require('./yaml_tests' + branchSuffix + '.json'), function (docs, filename) {
return new YamlFile(filename, docs);
});
});
};

View File

@ -1,65 +0,0 @@
var childProc = require('child_process');
var events = require('events');
var path = require('path');
var fs = require('fs');
var _ = require('../../../src/lib/utils');
var argv = require('./argv');
exports.start = function (cb) {
if (!argv.executable || !fs.existsSync(argv.executable)) {
return cb(new Error('unable to find elasticsearch executable, ' +
'set ES_HOME env var to the instalation path of elasticsearch'));
}
var server = childProc.spawn(
argv.executable,
[
'-f',
'-Des.cluster.name=' + argv.clusterName,
'-Des.path.data=' + argv.dataPath,
// '-Des.logger.level=DEBUG',
'-Des.discovery.zen.ping.multicast.enabled=false',
],
{
cwd: void 0,
env: process.env,
stdio: [
'ignore',
'pipe',
'pipe'
]
}
);
server.stdout.on('data', function onProcessData(line) {
line = line.toString().trim();
var match;
if (match = line.match(/\{inet\[\/?([^:]+):(\d+)\]\}/)) {
server.__hostname = match[1];
server.__port = match[2];
}
if (line.match(/started\s*$/m)) {
console.log('Personal ES Server started at', server.__hostname + ':' + server.__port);
server.stdout.removeListener('data', onProcessData);
server.stdout.resume();
cb(null, server);
}
});
server.stderr.on('data', function (line) {
console.error(line.toString().trim());
});
server.on('close', function (code) {
server.stdout.removeAllListeners();
server.stderr.removeAllListeners();
console.log('Personal ES Server Shutdown with exit code', code);
});
process.on('exit', function () {
server.kill();
});
};

File diff suppressed because it is too large Load Diff

View File

@ -57,7 +57,7 @@ describe('Http Connector', function () {
});
it('expects the host to have a protocol of http or https', function () {
(function () {
expect(function () {
var con = new HttpConnection(new Host('thrifty://es.com/stuff'));
}).to.throwError(/invalid protocol/i);
});
@ -172,9 +172,9 @@ describe('Http Connector', function () {
it('calls http based on the host', function (done) {
var con = new HttpConnection(new Host('http://google.com'));
con.request({}, function () {
http.request.callCount.should.eql(1);
https.request.callCount.should.eql(0);
http.request.lastCall.args[0].agent.should.be.an.instanceOf(KeepAliveAgent);
expect(http.request.callCount).to.be(1);
expect(https.request.callCount).to.be(0);
expect(http.request.lastCall.args[0].agent).to.be.a(KeepAliveAgent);
done();
});
});
@ -182,9 +182,9 @@ describe('Http Connector', function () {
it('calls https based on the host', function (done) {
var con = new HttpConnection(new Host('https://google.com'));
con.request({}, function () {
http.request.callCount.should.eql(0);
https.request.callCount.should.eql(1);
https.request.lastCall.args[0].agent.should.be.an.instanceOf(KeepAliveAgent.HttpsAgent);
expect(http.request.callCount).to.be(0);
expect(https.request.callCount).to.be(1);
expect(https.request.lastCall.args[0].agent).to.be.a(KeepAliveAgent.HttpsAgent);
done();
});
});

View File

@ -138,6 +138,10 @@ describe('Utils', function () {
it('handles leading _', function () {
expect(_.camelCase('_thing_one_')).to.eql('_thingOne');
});
it('works on numbers', function () {
expect(_.camelCase('version 1.0')).to.eql('version10');
});
});
describe('#studlyCase', function () {
@ -152,6 +156,10 @@ describe('Utils', function () {
it('handles leading _', function () {
expect(_.studlyCase('_thing_one_')).to.eql('_ThingOne');
});
it('works on numbers', function () {
expect(_.studlyCase('version 1.0')).to.eql('Version10');
});
});
describe('#snakeCase', function () {
@ -166,6 +174,10 @@ describe('Utils', function () {
it('handles leading _', function () {
expect(_.snakeCase('_thing_one_')).to.eql('_thing_one');
});
it('works on numbers', function () {
expect(_.snakeCase('version 1.0')).to.eql('version_1_0');
});
});
describe('#toLowerString', function () {