merged master
This commit is contained in:
@ -24,41 +24,51 @@ var esServer = null;
|
||||
|
||||
module.exports = {
|
||||
create: function create(cb) {
|
||||
if (argv.createServer || externalExists === false) {
|
||||
if (!esServer) {
|
||||
server.start(function (err, _server) {
|
||||
esServer = _server;
|
||||
if (err) {
|
||||
done(err);
|
||||
} else {
|
||||
doCreateClient(done);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
doCreateClient(done);
|
||||
}
|
||||
} else if (externalExists === void 0) {
|
||||
doCreateClient(function () {
|
||||
// create a client and ping the server for up to 15 seconds
|
||||
doCreateClient({
|
||||
logConfig: null
|
||||
}, function () {
|
||||
var attemptsRemaining = 30;
|
||||
var timeout = 500;
|
||||
|
||||
(function ping() {
|
||||
client.ping({
|
||||
requestTimeout: 1000
|
||||
maxRetries: 0,
|
||||
requestTimeout: 100
|
||||
}, function (err) {
|
||||
if (err instanceof es.errors.ConnectionFault) {
|
||||
externalExists = false;
|
||||
create(done);
|
||||
if (err && --attemptsRemaining) {
|
||||
setTimeout(ping, timeout);
|
||||
} else if (err) {
|
||||
cb(new Error('unable to establish contact with ES'));
|
||||
} else {
|
||||
done(err);
|
||||
// create a new client
|
||||
doCreateClient(function () {
|
||||
cb(void 0, client);
|
||||
});
|
||||
}
|
||||
});
|
||||
});
|
||||
} else {
|
||||
doCreateClient(done);
|
||||
}
|
||||
}());
|
||||
});
|
||||
|
||||
function done(err) {
|
||||
cb(err, client);
|
||||
}
|
||||
function doCreateClient(options, cb) {
|
||||
if (typeof options === 'function') {
|
||||
cb = options, options = {};
|
||||
}
|
||||
|
||||
var logConfig = _.has(options, 'logConfig')
|
||||
? options.logConfig
|
||||
: {
|
||||
type: BROWSER
|
||||
? 'console'
|
||||
: VERBOSE
|
||||
? 'tracer'
|
||||
: 'stdio',
|
||||
level: VERBOSE
|
||||
? 'trace'
|
||||
: 'warning',
|
||||
path: VERBOSE ? undefined : false
|
||||
};
|
||||
|
||||
function doCreateClient(cb) {
|
||||
// close existing client
|
||||
if (client) {
|
||||
client.close();
|
||||
@ -71,17 +81,7 @@ module.exports = {
|
||||
port: esServer ? esServer.__port : argv.port
|
||||
}
|
||||
],
|
||||
log: {
|
||||
type: BROWSER
|
||||
? 'console'
|
||||
: VERBOSE
|
||||
? 'tracer'
|
||||
: 'stdio',
|
||||
level: VERBOSE
|
||||
? 'trace'
|
||||
: 'warning',
|
||||
path: VERBOSE ? undefined : false
|
||||
}
|
||||
log: logConfig
|
||||
});
|
||||
|
||||
_.nextTick(cb);
|
||||
|
||||
22
test/unit_tests.html
Normal file
22
test/unit_tests.html
Normal file
@ -0,0 +1,22 @@
|
||||
<html>
|
||||
<head>
|
||||
<meta charset="utf-8">
|
||||
<title>Mocha Tests</title>
|
||||
<link rel="stylesheet" href="mocha.css" />
|
||||
</head>
|
||||
<body>
|
||||
<div id="mocha"></div>
|
||||
<script src="jquery.js"></script>
|
||||
<script src="expect.js"></script>
|
||||
<script src="mocha.js"></script>
|
||||
<script>mocha.setup('bdd')</script>
|
||||
<script src="test.array.js"></script>
|
||||
<script src="test.object.js"></script>
|
||||
<script src="test.xhr.js"></script>
|
||||
<script>
|
||||
mocha.checkLeaks();
|
||||
mocha.globals(['jQuery']);
|
||||
mocha.run();
|
||||
</script>
|
||||
</body>
|
||||
</html>
|
||||
5598
test/utils/mocha.js
Normal file
5598
test/utils/mocha.js
Normal file
File diff suppressed because it is too large
Load Diff
Reference in New Issue
Block a user