UNPKG

elasticsearch-watchdog

Version:

A watchdog of elasticsearch - cluster nodes' statuses monitor, auto restart, keep PRIMARY node unique.

145 lines (135 loc) 3.63 kB
var chai = require('chai'), should = chai.should(), expect = chai.expect, path = require('path'), Watchdog = require('../'), async = require('async'), spawn = require('child_process').spawn; function runCmd(cmd, args, callback, detached) { var proc = spawn(process.execPath, [ path.resolve(__dirname, '..', 'bin/watchdog'), cmd ].concat(args), {detached:!!detached}); if (!!detached) { proc.unref(); callback(); } else { proc.stdout.once('data', function (data) { callback(data); proc.kill(); }); } } describe('start watching', function () { var confPath1, confPath2; before(function(){ confPath1 = path.resolve(__dirname, '..', 'example/confs/cluster1.yml'); confPath2 = path.resolve(__dirname, '..', 'example/confs/cluster2.yml'); }); after(function(){ confPath1 = null; confPath2 = null; }); describe('with no-daemon', function (){ it('should responds with information', function(done){ runCmd('start', [ confPath1, '--no-daemon' ], function(data){ expect(data).exist; expect(data.toString()).to.contain('CHECKING'); done(); }) }); }); describe('with daemonic', function (){ it('should start normally and stop it by uid after test', function (done) { async.waterfall([ // start daemonic process function (next) { runCmd('start', [ confPath2 ], function () { next(); }, true); }, // delay. function (next) { setTimeout(next, 1000); }, // list function (next) { runCmd('ls', ['--no-format'], function (data) { expect(data).exist; try { data = JSON.parse(data.toString()); expect(data).have.length(1); next(null, data[0].uid); } catch (err) { next(err); } }) }, // stop it. function (uid, next) { runCmd('stop', [uid], function (data) { expect(data).exist; expect(data.toString()).to.contain('No puppy out door.'); next(); }); } ], function (err, result) { expect(err).not.exist; done(); }) }); it('start two watchdogs, should well balanced and stop all after test', function (done) { async.waterfall([ // start daemonic process function (next) { runCmd('start', [ confPath1 ], function () { next(); }, true); }, // start daemonic process function (next) { runCmd('start', [ confPath2 ], function () { next(); }, true); }, // delay. function (next) { setTimeout(next, 1000); }, // list function (next) { runCmd('ls', ['--no-format'], function (data) { expect(data).exist; try { data = JSON.parse(data.toString()); expect(data).have.length(2); next(); } catch (err) { next(err); } }) }, // stop all. function (next) { runCmd('stop', ['all'], function (data) { expect(data).exist; expect(data.toString()).to.contain('No puppy out door.'); next(); }); } ], function (err, result) { expect(err).not.exist; done(); }) }); }); });