diff options
| author | yo mama <pepper@scannerjammer.com> | 2015-04-04 01:00:59 -0700 |
|---|---|---|
| committer | yo mama <pepper@scannerjammer.com> | 2015-04-04 01:00:59 -0700 |
| commit | c7c22e3db1c826bcfb2bc66651ec480aae0d4ae0 (patch) | |
| tree | 8546df448afef40d3814d2581f4dacff7cebb87f /node_modules/forever/test/worker/multiple-workers-test.js | |
Diffstat (limited to 'node_modules/forever/test/worker/multiple-workers-test.js')
| -rw-r--r-- | node_modules/forever/test/worker/multiple-workers-test.js | 98 |
1 files changed, 98 insertions, 0 deletions
diff --git a/node_modules/forever/test/worker/multiple-workers-test.js b/node_modules/forever/test/worker/multiple-workers-test.js new file mode 100644 index 0000000..dca1685 --- /dev/null +++ b/node_modules/forever/test/worker/multiple-workers-test.js @@ -0,0 +1,98 @@ +/* + * multiple-workers-test.js: Tests for spawning multiple workers with forever + * + * (C) 2010 Nodejitsu Inc. + * MIT LICENCE + * + */ + +var assert = require('assert'), + net = require('net'), + path = require('path'), + request = require('request'), + vows = require('vows'), + forever = require('../../lib/forever'); + +var children = [], + pids; + +// +// Helper function test requests against children. +// +function assertRunning(port, i) { + return { + topic: function () { + request('http://127.0.0.1:' + port, this.callback); + }, + "should respond with `i know nodejitsu`": function (err, res, body) { + assert.isNull(err); + assert.equal(res.statusCode, 200); + assert.equal(body, 'hello, i know nodejitsu.'); + }, + "stop the child process": function () { + children[i].stop(); + } + } +} + +vows.describe('forever/workers/multiple').addBatch({ + "When using forever": { + "and spawning two processes using the same script": { + topic: function () { + var that = this, + script = path.join(__dirname, '..', 'fixtures', 'server.js'); + + children[0] = new (forever.Monitor)(script, { + silent: true, + maxRestart: 1, + options: [ "--port=8080"] + }); + + children[1] = new (forever.Monitor)(script, { + silent: true, + maxRestart: 1, + options: [ "--port=8081"] + }); + + children[0].on('start', function () { + children[1].on('start', function () { + pids = children.map(function (child) { + return child.child.pid; + }); + + setTimeout(function () { + forever.startServer(children[0], children[1], that.callback); + }, 1000); + }); + + children[1].start(); + }); + + children[0].start(); + }, + "should respond with no error": function (err, workers) { + assert.lengthOf(workers, 2); + assert.equal(workers[0].monitor, children[0]); + assert.equal(workers[1].monitor, children[1]); + workers.forEach(function (worker) { + assert.instanceOf(worker, forever.Worker); + }); + }, + "requests against the first child": assertRunning(8080, 0), + "requests against the second child": assertRunning(8081, 1) + // + // TODO: We should cleanup these processes. + // + } + }, +}).addBatch({ + "Once the stop attempt has been made": { + topic: function () { + setTimeout(this.callback, 200); + }, + "the processes should be dead": function () { + assert.isFalse(forever.checkProcess(pids[0])); + assert.isFalse(forever.checkProcess(pids[1])); + } + } +}).export(module); |
