From ef596727c0c473a534b07d116fd93d54da81a872 Mon Sep 17 00:00:00 2001 From: indexzero Date: Sun, 10 Jul 2011 23:17:48 -0400 Subject: [PATCH] [test] Updated tests for refactor in previous commit --- test/fixtures/test-hook.js | 2 +- test/forever-test.js | 6 ++--- test/helpers.js | 21 ----------------- test/hook-test.js | 9 ++++--- test/multiple-processes-test.js | 42 ++++++++++++++++++--------------- test/spawn-options-test.js | 4 +--- test/spin-test.js | 2 +- 7 files changed, 32 insertions(+), 54 deletions(-) diff --git a/test/fixtures/test-hook.js b/test/fixtures/test-hook.js index 7cbdc07b..7b793a5a 100644 --- a/test/fixtures/test-hook.js +++ b/test/fixtures/test-hook.js @@ -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)); }); }; \ No newline at end of file diff --git a/test/forever-test.js b/test/forever-test.js index 7d05b378..c7084ee7 100644 --- a/test/forever-test.js +++ b/test/forever-test.js @@ -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( @@ -79,6 +79,4 @@ vows.describe('forever').addBatch({ } } } -}).addBatch( - helpers.assertEmpty() -).export(module); \ No newline at end of file +}).export(module); \ No newline at end of file diff --git a/test/helpers.js b/test/helpers.js index 57d15db5..a96a86d2 100644 --- a/test/helpers.js +++ b/test/helpers.js @@ -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); - } - } - } - } }; \ No newline at end of file diff --git a/test/hook-test.js b/test/hook-test.js index 499c468f..e7f223f4 100644 --- a/test/hook-test.js +++ b/test/hook-test.js @@ -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); } } } diff --git a/test/multiple-processes-test.js b/test/multiple-processes-test.js index 1780b98f..a35ddfd8 100644 --- a/test/multiple-processes-test.js +++ b/test/multiple-processes-test.js @@ -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'); @@ -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(); } diff --git a/test/spawn-options-test.js b/test/spawn-options-test.js index 28ad2f96..67dd54b1 100644 --- a/test/spawn-options-test.js +++ b/test/spawn-options-test.js @@ -71,6 +71,4 @@ vows.describe('forever').addBatch({ } } } -}).addBatch( - helpers.assertEmpty() -).export(module); +}).export(module); diff --git a/test/spin-test.js b/test/spin-test.js index b1fa21be..4d983002 100644 --- a/test/spin-test.js +++ b/test/spin-test.js @@ -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();