Permalink
Browse files

[minor test] Added tests for multiple processes from a single node pr…

…ocess
  • Loading branch information...
indexzero committed Apr 20, 2011
1 parent 1c16e81 commit 6e52e03b0fe5bba0587e717b8f9fe0a1afc68402
Showing with 56 additions and 3 deletions.
  1. +5 −2 lib/forever.js
  2. +5 −1 lib/forever/monitor.js
  3. +46 −0 test/multiple-processes.js
View
@@ -297,12 +297,15 @@ forever.stopAll = function (format) {
};
//
// ### function list (format)
// ### function list (format, procs)
// #### @format {boolean} If set, will return a formatted string of data
// #### @procs {Array} Set of processes to list format.
// Returns the list of all process data managed by forever.
//
forever.list = function (format, procs) {
var formatted = [], procs = procs || getAllProcesses();
var formatted = [];
procs = procs || getAllProcesses();
if (!procs) return null;
if (format) {
View
@@ -97,7 +97,11 @@ Monitor.prototype.start = function (restart) {
this.ctime = Date.now();
this.child = child;
this.running = true;
this.emit(restart ? 'restart' : 'start', self);
this.once('save', function () {
self.emit(restart ? 'restart' : 'start', self);
});
this.save();
// Hook all stream data and process it
View
@@ -0,0 +1,46 @@
/*
* forever-test.js: Tests for forever module
*
* (C) 2010 and Charlie Robbins
* MIT LICENCE
*
*/
require.paths.unshift(require('path').join(__dirname, '..', 'lib'));
var sys = require('sys'),
assert = require('assert'),
path = require('path'),
vows = require('vows'),
forever = require('forever');
vows.describe('forever').addBatch({
"When using forever": {
"and spawning two processes using the same script": {
topic: function () {
var that = this,
script = path.join(__dirname, '..', 'examples', 'server.js'),
child1 = new (forever.Forever)(script, { 'options': [ "--port=8080"] });
var tidy = forever.cleanUp(true);
tidy.on('cleanUp', function () {
child1.on('start', function () {
var child2 = new (forever.Forever)(script, { 'options': [ "--port=8081"] });
child2.on('start', function () {
that.callback(null, forever.list(false));
});
child2.start();
});
child1.start();
});
},
"should spawn both processes appropriately": function (err, procs) {
assert.isNull(err);
assert.length(procs, 2);
}
}
},
}).export(module);

0 comments on commit 6e52e03

Please sign in to comment.