Skip to content

Commit

Permalink
[minor test] Added tests for multiple processes from a single node pr…
Browse files Browse the repository at this point in the history
…ocess
  • Loading branch information
indexzero committed Apr 20, 2011
1 parent 1c16e81 commit 6e52e03
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 3 deletions.
7 changes: 5 additions & 2 deletions lib/forever.js
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
6 changes: 5 additions & 1 deletion lib/forever/monitor.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
46 changes: 46 additions & 0 deletions test/multiple-processes.js
Original file line number Diff line number Diff line change
@@ -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.