mirror of
https://github.com/Unitech/pm2.git
synced 2025-12-08 20:35:53 +00:00
add test for interactor - update tests
This commit is contained in:
parent
16ed01955b
commit
b4a4b6fa08
@ -818,6 +818,7 @@ CLI.subscribe = function(email) {
|
||||
|
||||
WatchDog.createConfFile(email, function() {
|
||||
printOut('PM2 is now ready for monitoring via PING strategy. To enable it, please restart pm2');
|
||||
printOut('(update procedure : pm2 dump; pm2 kill ; pm2 resurrect)');
|
||||
printOut('For more informations : https://github.com/Unitech/pm2#builtin-remote-monitoring');
|
||||
exitCli(cst.SUCCESS_EXIT);
|
||||
});
|
||||
|
||||
@ -118,16 +118,22 @@ function exec(script, outFile, errFile) {
|
||||
}
|
||||
|
||||
// Notify master that an uncaughtException has been catched
|
||||
process.send({
|
||||
type : 'uncaughtException',
|
||||
stack : err.stack,
|
||||
err : {
|
||||
type: err.type,
|
||||
stack: err.stack,
|
||||
arguments: err.arguments,
|
||||
message: err.message
|
||||
}
|
||||
});
|
||||
try {
|
||||
process.send({
|
||||
type : 'uncaughtException',
|
||||
stack : err.stack,
|
||||
err : {
|
||||
type: err.type,
|
||||
stack: err.stack,
|
||||
arguments: err.arguments,
|
||||
message: err.message
|
||||
}
|
||||
});
|
||||
} catch(e) {
|
||||
try {
|
||||
stderr.write('Channel is already closed can\'t broadcast error', err);
|
||||
} catch(e) {}
|
||||
}
|
||||
|
||||
if (!process.listeners('uncaughtException').filter(function (listener) {
|
||||
return listener !== uncaughtListener;
|
||||
|
||||
@ -65,7 +65,8 @@
|
||||
"main": "index.js",
|
||||
"scripts": {
|
||||
"test": "bash ./test/cli.sh && bash ./test/json_file.sh && bash ./test/harmony.sh && bash ./test/reload.sh && bash ./test/right-exit-code.sh && bash ./test/log-reload.sh && bash ./test/gracefulReload.sh && bash ./test/cli2.sh && bash ./test/misc.sh && bash ./test/watchdog.sh && bash ./test/fork.sh && bash ./test/infinite_loop.sh && NODE_ENV=test ./node_modules/mocha/bin/mocha test",
|
||||
"install" : "node scripts/install.js"
|
||||
"install" : "node scripts/install.js",
|
||||
"update" : "node scripts/install.js"
|
||||
},
|
||||
"keywords": [
|
||||
"cli",
|
||||
|
||||
102
test/interactor.mocha.js
Normal file
102
test/interactor.mocha.js
Normal file
@ -0,0 +1,102 @@
|
||||
|
||||
|
||||
var Satan;
|
||||
var should = require('should');
|
||||
var assert = require('better-assert');
|
||||
var path = require('path');
|
||||
var ipm2;
|
||||
var arr = [];
|
||||
|
||||
setTimeout(function() {
|
||||
process.exit(0);
|
||||
}, 15000);
|
||||
|
||||
describe('Interactor', function() {
|
||||
|
||||
after(function(done) {
|
||||
Satan.killDaemon(function() {
|
||||
setTimeout(done, 400);
|
||||
});
|
||||
});
|
||||
|
||||
it('should auto instancy itself, fire event and kill daemon', function(done) {
|
||||
Satan = require('../lib/Satan');
|
||||
Satan.start();
|
||||
process.once('satan:client:ready', function() {
|
||||
console.log('Client ready');
|
||||
Satan.killDaemon(function() {
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
it('should start daemon', function(done) {
|
||||
Satan.launchDaemon(function(err, child) {
|
||||
assert(err == null);
|
||||
assert(typeof child.pid == 'number');
|
||||
Satan.pingDaemon(function(online) {
|
||||
assert(online == true);
|
||||
done();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe('STRING INTERACTION', function() {
|
||||
it('should launch a process', function(done) {
|
||||
Satan.executeRemote('prepare', {
|
||||
pm_exec_path : path.resolve(process.cwd(), 'test/fixtures/echo.js'),
|
||||
pm_err_log_path : path.resolve(process.cwd(), 'test/errLog.log'),
|
||||
pm_out_log_path : path.resolve(process.cwd(), 'test/outLog.log'),
|
||||
pm_pid_path : path.resolve(process.cwd(), 'test/child'),
|
||||
instances : 4
|
||||
}, function(err, procs) {
|
||||
assert(err == null);
|
||||
assert(procs.length == 4);
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
it('should ipm2 connect to God', function(done) {
|
||||
ipm2 = require('pm2-interface')();
|
||||
|
||||
ipm2.on('ready', function() {
|
||||
console.log('Connected to pm2');
|
||||
|
||||
done();
|
||||
ipm2.bus.on('*', function(event, data) {
|
||||
arr.push({
|
||||
event : event,
|
||||
data : data
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
it('should output log', function(done) {
|
||||
setTimeout(function() {
|
||||
arr.some(function(dt) {
|
||||
if (dt.event == 'log:out' && dt.data) {
|
||||
dt.data.should.be.a.String;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
done();
|
||||
}, 1000);
|
||||
});
|
||||
|
||||
it('should output log', function(done) {
|
||||
arr.some(function(dt) {
|
||||
if (dt.event == 'log:err' && dt.data) {
|
||||
dt.data.should.be.a.String;
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
});
|
||||
|
||||
done();
|
||||
});
|
||||
});
|
||||
|
||||
});
|
||||
@ -52,7 +52,7 @@ $pm2 kill
|
||||
|
||||
rm outmerge*
|
||||
|
||||
$pm2 start echo.js -i max -o outmerge.log
|
||||
$pm2 start echo.js -i 4 -o outmerge.log
|
||||
|
||||
cat outmerge.log > /dev/null
|
||||
ispec 'file outmerge.log should not exist'
|
||||
@ -68,7 +68,7 @@ $pm2 kill
|
||||
|
||||
rm outmerge*
|
||||
|
||||
$pm2 start echo.js -i max -o outmerge.log --merge-logs
|
||||
$pm2 start echo.js -i 4 -o outmerge.log --merge-logs
|
||||
|
||||
cat outmerge.log > /dev/null
|
||||
spec 'file outmerge.log should exist'
|
||||
@ -77,5 +77,3 @@ cat outmerge-0.log > /dev/null
|
||||
ispec 'file outmerge-0.log should not exist'
|
||||
|
||||
rm outmerge*
|
||||
|
||||
|
||||
|
||||
@ -28,7 +28,6 @@ describe('Satan', function() {
|
||||
assert(err == null);
|
||||
assert(typeof child.pid == 'number');
|
||||
Satan.pingDaemon(function(online) {
|
||||
console.log(online);
|
||||
assert(online == true);
|
||||
done();
|
||||
});
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user