Skip to content

Commit

Permalink
[test] Updated tests for refactor in previous commit
Browse files Browse the repository at this point in the history
  • Loading branch information
indexzero committed Jul 11, 2011
1 parent 7ae870e commit ef59672
Show file tree
Hide file tree
Showing 7 changed files with 32 additions and 54 deletions.
2 changes: 1 addition & 1 deletion test/fixtures/test-hook.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,6 @@ util.inherits(TestHook, events.EventEmitter);
TestHook.prototype.attach = function (monitor) {
var self = this;
monitor.on('exit', function () {
self.emit.apply(['hook-exit'].concat(arguments));
self.emit.apply(self, ['hook-exit'].concat(arguments));
});
};
6 changes: 2 additions & 4 deletions test/forever-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ vows.describe('forever').addBatch({
assert.equal(child.max, 10);
assert.isTrue(child.silent);
assert.isFunction(child.start);
assert.isFunction(child.save);
assert.isObject(child.data);
assert.isFunction(child.stop);
},
"running error-on-timer sample three times": helpers.assertTimes(
Expand Down Expand Up @@ -79,6 +79,4 @@ vows.describe('forever').addBatch({
}
}
}
}).addBatch(
helpers.assertEmpty()
).export(module);
}).export(module);
21 changes: 0 additions & 21 deletions test/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -24,25 +24,4 @@ helpers.assertTimes = function (script, times, options) {
assert.equal(child.times, times);
}
}
};

helpers.assertEmpty = function () {
return {
"When the tests are over": {
"a call to forever.list()": {
topic: function () {
var that = this;
var tidy = forever.cleanUp(true, true);

tidy.on('cleanUp', function () {
that.callback(null, forever.list(false));
});
},
"should respond with no processes": function (err, procs) {
assert.isNull(err);
assert.isNull(procs);
}
}
}
}
};
9 changes: 4 additions & 5 deletions test/hook-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,20 @@
"with a simple hook": {
topic: function () {
var script = path.join(__dirname, '..', 'examples', 'always-throw.js'),
hook = new TestHook(),
child;

child = new (forever.Monitor)(script, {
silent: true,
max: 1,
hooks: [
new TestHook()
]
hooks: [hook]
});

child.on('exit', this.callback.bind({}, null));
hook.on('hook-exit', this.callback.bind(null, null));
child.start();
},
"should raise the `hook-exit` event": function (err, child, spinning) {
assert.isTrue(spinning);
assert.isNull(err);
}
}
}
Expand Down
42 changes: 23 additions & 19 deletions test/multiple-processes-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@
*
*/

var sys = require('sys'),
assert = require('assert'),
var assert = require('assert'),
net = require('net'),
path = require('path'),
sys = require('sys'),
vows = require('vows'),
forever = require('../lib/forever');

Expand All @@ -25,28 +26,31 @@ vows.describe('forever/multiple-processes').addBatch({
options: [ "--port=8080"]
});

var tidy = forever.cleanUp(true);
tidy.on('cleanUp', function () {
that.child1.on('start', function () {
that.child2 = new (forever.Monitor)(script, {
silent: true,
maxRestart: 1,
options: [ "--port=8081"]
});

that.child2.on('start', function () {
that.callback(null, forever.list(false));
that.child1.on('start', function () {
that.child2 = new (forever.Monitor)(script, {
silent: true,
maxRestart: 1,
options: [ "--port=8081"]
});

that.child2.on('start', function () {
forever.startServer(that.child1, that.child2, function (err, server, socketPath) {
var socket = new net.Socket();
socket.on('data', that.callback.bind(null, null));
socket.on('error', that.callback);
socket.connect(socketPath);
});

that.child2.start();
});

that.child1.start();
});
that.child2.start();
});

that.child1.start();
},
"should spawn both processes appropriately": function (err, procs) {
"should spawn both processes appropriately": function (err, data) {
assert.isNull(err);
assert.length(procs, 2);
data = JSON.parse(data.toString());
assert.length(data.monitors, 2);
this.child1.stop();
this.child2.stop();
}
Expand Down
4 changes: 1 addition & 3 deletions test/spawn-options-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,4 @@ vows.describe('forever').addBatch({
}
}
}
}).addBatch(
helpers.assertEmpty()
).export(module);
}).export(module);
2 changes: 1 addition & 1 deletion test/spin-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ vows.describe('forever/spin-restart').addBatch({
"with no spinSleepTime specified": {
topic: function () {
var script = path.join(__dirname, '..', 'examples', 'always-throw.js'),
child = new (forever.Monitor)(script, { silent: true, max: 3 });
child = new (forever.Monitor)(script, { silent: true, minUptime: 2000, max: 3 });

child.on('exit', this.callback.bind({}, null));
child.start();
Expand Down

0 comments on commit ef59672

Please sign in to comment.