mirror of
https://github.com/mgerb/mywebsite
synced 2026-01-13 19:12:49 +00:00
Added files
This commit is contained in:
51
node_modules/forever/test/cli-test
generated
vendored
Executable file
51
node_modules/forever/test/cli-test
generated
vendored
Executable file
@@ -0,0 +1,51 @@
|
||||
#!/usr/bin/env bash
|
||||
|
||||
#
|
||||
# cli-test: Tests for forever CLI
|
||||
#
|
||||
# (C) 2012 Charlie Robbins & the Contributors
|
||||
# MIT LICENSE
|
||||
#
|
||||
|
||||
# Yes, we have tests in bash. How mad science is that?
|
||||
|
||||
alias forever=bin/forever
|
||||
script="test/fixtures/log-on-interval.js"
|
||||
|
||||
function fail {
|
||||
echo "\033[31m ✘ $1\033[0m"
|
||||
exit 1
|
||||
}
|
||||
|
||||
function success {
|
||||
echo "\033[32m ✔ $1\033[0m"
|
||||
}
|
||||
|
||||
function spec {
|
||||
[ $? -eq 0 ] || fail "$1"
|
||||
success "$1"
|
||||
}
|
||||
|
||||
echo "\033[1mRunning tests:\033[0m"
|
||||
|
||||
# First kill all processes and remove forever directory to ensure clean
|
||||
# environment
|
||||
forever stopall
|
||||
rm -rf ~/.forever
|
||||
|
||||
# Spawn some process
|
||||
forever start "$script"
|
||||
|
||||
# Assert that forever actually spawned a process and that it's in `forever list`
|
||||
sleep 1 # it takes some time until process appears in `forever list`
|
||||
forever list | grep "$script"
|
||||
spec "\`forever list\` should contain spawned process"
|
||||
|
||||
# `forever stop` should output process it stopped...
|
||||
forever stop 0 | grep "$script"
|
||||
spec "\`forever stop 0\` should contain stopped process"
|
||||
|
||||
# ... and actually stop it
|
||||
forever list | grep -v "$script"
|
||||
spec "\`forever stop 0\` should actually stop the process"
|
||||
|
||||
62
node_modules/forever/test/core/daemonic-inheritance-test.js
generated
vendored
Normal file
62
node_modules/forever/test/core/daemonic-inheritance-test.js
generated
vendored
Normal file
@@ -0,0 +1,62 @@
|
||||
/*
|
||||
* daemonic-inheritance-test.js: Tests for configuration inheritance of forever.startDaemon()
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* MIT LICENCE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
forever = require('../../lib/forever');
|
||||
|
||||
//
|
||||
// n.b. (indexzero): The default root is `~/.forever` so this
|
||||
// actually is a valid, non-default test path.
|
||||
//
|
||||
var myRoot = path.resolve(process.env.HOME, '.forever_root');
|
||||
|
||||
vows.describe('forever/core/startDaemon').addBatch({
|
||||
"When using forever" : {
|
||||
"the startDaemon() method with customized configuration" : {
|
||||
topic: function () {
|
||||
if (!fs.existsSync(myRoot)) {
|
||||
fs.mkdirSync(myRoot);
|
||||
}
|
||||
|
||||
forever.load({root:myRoot});
|
||||
|
||||
forever.startDaemon(path.join(__dirname, '..', 'fixtures', 'log-on-interval.js'));
|
||||
setTimeout(function (that) {
|
||||
forever.list(false, that.callback);
|
||||
}, 2000, this);
|
||||
},
|
||||
"should respond with 1 process": function (err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.isArray(procs);
|
||||
assert.equal(procs.length, 1);
|
||||
},
|
||||
"and logs/pids/socks are all piping into the customized root": function (err, procs) {
|
||||
assert.equal(procs[0].logFile.indexOf(myRoot), 0);
|
||||
assert.equal(procs[0].pidFile.indexOf(myRoot), 0);
|
||||
assert.equal(procs[0].socket.indexOf(myRoot), 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When the tests are over" : {
|
||||
"stop all forever processes" : {
|
||||
topic: function () {
|
||||
forever.load({root:myRoot});
|
||||
forever.stopAll().on('stopAll', this.callback.bind(null, null));
|
||||
},
|
||||
"should stop the correct number of procs": function (err, procs) {
|
||||
assert.isArray(procs);
|
||||
assert.lengthOf(procs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
60
node_modules/forever/test/core/start-stop-relative-test.js
generated
vendored
Normal file
60
node_modules/forever/test/core/start-stop-relative-test.js
generated
vendored
Normal file
@@ -0,0 +1,60 @@
|
||||
/*
|
||||
* start-stop-relative.js: start or stop forever using relative paths, the script path could be start with './', '../' ...
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* MIT LICENCE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
forever = require('../../lib/forever');
|
||||
|
||||
function runCmd(cmd, args) {
|
||||
var proc = spawn(process.execPath, [
|
||||
path.resolve(__dirname, '../../', 'bin/forever'),
|
||||
cmd
|
||||
].concat(args), {detached: true});
|
||||
|
||||
proc.unref();
|
||||
}
|
||||
|
||||
vows.describe('forever/core/start-stop-peaceful').addBatch({
|
||||
"When using forever" : {
|
||||
"to run script with relative script path" : {
|
||||
topic: function () {
|
||||
runCmd('start', [
|
||||
'./test/fixtures/log-on-interval.js'
|
||||
]);
|
||||
setTimeout(function (that) {
|
||||
forever.list(false, that.callback);
|
||||
}, 2000, this);
|
||||
},
|
||||
"the startup should works fine": function (err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.isArray(procs);
|
||||
assert.equal(procs.length, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When the script is running" : {
|
||||
"try to stop with relative script path" : {
|
||||
topic: function () {
|
||||
runCmd('stop', [
|
||||
'./test/fixtures/log-on-interval.js'
|
||||
]);
|
||||
setTimeout(function (that) {
|
||||
forever.list(false, that.callback);
|
||||
}, 2000, this);
|
||||
},
|
||||
"the shut down should works fine": function (err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.isNull(procs);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
77
node_modules/forever/test/core/stopall-peaceful-test.js
generated
vendored
Normal file
77
node_modules/forever/test/core/stopall-peaceful-test.js
generated
vendored
Normal file
@@ -0,0 +1,77 @@
|
||||
/*
|
||||
* stopall-peaceful-test.js: tests if `forever start` followed by `forever stopall` works.
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* MIT LICENCE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
forever = require('../../lib/forever');
|
||||
|
||||
function runCmd(cmd, args) {
|
||||
var proc = spawn(process.execPath, [
|
||||
path.resolve(__dirname, '../../', 'bin/forever'),
|
||||
cmd
|
||||
].concat(args), {detached: true});
|
||||
proc.unref();
|
||||
return proc;
|
||||
}
|
||||
|
||||
vows.describe('forever/core/stopall-peaceful').addBatch({
|
||||
"When using forever" : {
|
||||
"to run script with 100% exit" : {
|
||||
topic: function () {
|
||||
runCmd('start', [
|
||||
'./test/fixtures/cluster-fork-mode.js'
|
||||
]);
|
||||
setTimeout(function (that) {
|
||||
forever.list(false, that.callback);
|
||||
}, 2000, this);
|
||||
},
|
||||
"the script should be marked as `STOPPED`": function (err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.isArray(procs);
|
||||
assert.equal(procs.length, 1);
|
||||
assert.ok(!procs[0].running);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When the script is running" : {
|
||||
"try to stop all" : {
|
||||
topic: function () {
|
||||
var that = this;
|
||||
forever.list(false, function(err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.isArray(procs);
|
||||
assert.equal(procs.length, 1);
|
||||
// get pid.
|
||||
var pid = procs[0].pid;
|
||||
// run command
|
||||
var cmd = runCmd('stopall', []);
|
||||
cmd.stdout.on('data', onData);
|
||||
//listen on the `data` event.
|
||||
function onData(data) {
|
||||
// check whether pid exists or not.
|
||||
var line = data.toString().replace (/[\n\r\t\s]+/g, ' ');
|
||||
if (line && line.search(new RegExp(pid)) > 0) {
|
||||
that.callback(null, true);
|
||||
cmd.stdout.removeListener('data', onData);
|
||||
}
|
||||
// if pid did not exist, that means CLI has crashed, and no output was printed.
|
||||
// vows will raise an Asynchronous Error.
|
||||
}
|
||||
});
|
||||
},
|
||||
"the shut down should works fine": function (err, peaceful) {
|
||||
assert.isNull(err);
|
||||
assert.ok(peaceful);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
78
node_modules/forever/test/core/stopbypid-peaceful-test.js
generated
vendored
Normal file
78
node_modules/forever/test/core/stopbypid-peaceful-test.js
generated
vendored
Normal file
@@ -0,0 +1,78 @@
|
||||
/*
|
||||
* stopbypid-peaceful-test.js: tests if `forever start` followed by `forever stop <pid>` works.
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* MIT LICENCE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
fs = require('fs'),
|
||||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
forever = require('../../lib/forever');
|
||||
|
||||
function runCmd(cmd, args) {
|
||||
var proc = spawn(process.execPath, [
|
||||
path.resolve(__dirname, '../../', 'bin/forever'),
|
||||
cmd
|
||||
].concat(args), {detached: true});
|
||||
proc.unref();
|
||||
return proc;
|
||||
}
|
||||
|
||||
vows.describe('forever/core/stopbypid-peaceful').addBatch({
|
||||
"When using forever" : {
|
||||
"to run script with 100% exit" : {
|
||||
topic: function () {
|
||||
runCmd('start', [
|
||||
'./test/fixtures/log-on-interval.js'
|
||||
]);
|
||||
setTimeout(function (that) {
|
||||
forever.list(false, that.callback);
|
||||
}, 2000, this);
|
||||
},
|
||||
"the script should be running": function (err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.isArray(procs);
|
||||
assert.equal(procs.length, 1);
|
||||
assert.ok(procs[0].running);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When the script is running" : {
|
||||
"try to stop by pid" : {
|
||||
topic: function () {
|
||||
var that = this;
|
||||
forever.list(false, function(err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.isArray(procs);
|
||||
assert.equal(procs.length, 1);
|
||||
// get pid.
|
||||
var pid = procs[0].pid;
|
||||
// run command
|
||||
var cmd = runCmd('stop', [pid]);
|
||||
cmd.stdout.on('data', onData);
|
||||
cmd.stderr.pipe(process.stderr);
|
||||
//listen on the `data` event.
|
||||
function onData(data) {
|
||||
// check whether pid exists or not.
|
||||
var line = data.toString().replace (/[\n\r\t\s]+/g, ' ');
|
||||
if (line && line.search(new RegExp(pid)) > 0) {
|
||||
that.callback(null, true);
|
||||
cmd.stdout.removeListener('data', onData);
|
||||
}
|
||||
// if pid did not exist, that means CLI has crashed, and no output was printed.
|
||||
// vows will raise an Asynchronous Error.
|
||||
}
|
||||
});
|
||||
},
|
||||
"the shut down should works fine": function (err, peaceful) {
|
||||
assert.isNull(err);
|
||||
assert.ok(peaceful);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
47
node_modules/forever/test/core/tail-stopall-test.js
generated
vendored
Normal file
47
node_modules/forever/test/core/tail-stopall-test.js
generated
vendored
Normal file
@@ -0,0 +1,47 @@
|
||||
/*
|
||||
* tail-stopall-test.js: Tests for forever.tail() and forever.stopAll()
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* MIT LICENCE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
spawn = require('child_process').spawn,
|
||||
vows = require('vows'),
|
||||
forever = require('../../lib/forever');
|
||||
|
||||
vows.describe('forever/core/tail').addBatch({
|
||||
"When using forever": {
|
||||
"the tail() method": {
|
||||
topic: function () {
|
||||
var that = this;
|
||||
|
||||
that.child = spawn('node', [path.join(__dirname, '..', 'fixtures', 'start-daemon.js')]);
|
||||
setTimeout(function () {
|
||||
forever.tail(0, { length: 1 }, that.callback);
|
||||
}, 2000);
|
||||
},
|
||||
"should respond with logs for the script": function (err, procs) {
|
||||
assert.isNull(err);
|
||||
assert.equal(typeof procs, 'object');
|
||||
assert.ok(procs.file);
|
||||
assert.ok(procs.pid);
|
||||
assert.ok(procs.line);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).addBatch({
|
||||
"When the tests are over": {
|
||||
"stop all forever processes": {
|
||||
topic: function () {
|
||||
forever.stopAll().on('stopAll', this.callback.bind(null, null));
|
||||
},
|
||||
"should stop the correct number of procs": function (err, procs) {
|
||||
assert.isArray(procs);
|
||||
assert.lengthOf(procs, 1);
|
||||
}
|
||||
}
|
||||
}
|
||||
}).export(module);
|
||||
2
node_modules/forever/test/fixtures/cluster-fork-mode.js
generated
vendored
Normal file
2
node_modules/forever/test/fixtures/cluster-fork-mode.js
generated
vendored
Normal file
@@ -0,0 +1,2 @@
|
||||
var cluster = require('cluster');
|
||||
console.log(cluster.isMaster ? 'master fork':'cluster fork');
|
||||
3
node_modules/forever/test/fixtures/log-on-interval.js
generated
vendored
Normal file
3
node_modules/forever/test/fixtures/log-on-interval.js
generated
vendored
Normal file
@@ -0,0 +1,3 @@
|
||||
setInterval(function () {
|
||||
console.log('Logging at ' + Date.now());
|
||||
}, 100);
|
||||
16
node_modules/forever/test/fixtures/server.js
generated
vendored
Normal file
16
node_modules/forever/test/fixtures/server.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
var util = require('util'),
|
||||
http = require('http'),
|
||||
argv = require('optimist').argv;
|
||||
|
||||
var port = argv.p || argv.port || 80;
|
||||
|
||||
http.createServer(function (req, res) {
|
||||
console.log(req.method + ' request: ' + req.url);
|
||||
res.writeHead(200, {'Content-Type': 'text/plain'});
|
||||
res.write('hello, i know nodejitsu.');
|
||||
res.end();
|
||||
}).listen(port);
|
||||
|
||||
/* server started */
|
||||
util.puts('> hello world running on port ' + port);
|
||||
|
||||
16
node_modules/forever/test/fixtures/start-daemon.js
generated
vendored
Normal file
16
node_modules/forever/test/fixtures/start-daemon.js
generated
vendored
Normal file
@@ -0,0 +1,16 @@
|
||||
/*
|
||||
* start-daemon.js: Simple test fixture for spawning log-on-interval.js as a daemon
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* MIT LICENCE
|
||||
*
|
||||
*/
|
||||
|
||||
var path = require('path'),
|
||||
forever = require('../../lib/forever');
|
||||
|
||||
var monitor = forever.startDaemon(path.join(__dirname, 'log-on-interval.js'));
|
||||
|
||||
monitor.on('start', function () {
|
||||
forever.startServer(monitor);
|
||||
});
|
||||
93
node_modules/forever/test/helpers/macros.js
generated
vendored
Normal file
93
node_modules/forever/test/helpers/macros.js
generated
vendored
Normal file
@@ -0,0 +1,93 @@
|
||||
/*
|
||||
* macros.js: Test macros for the forever module
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* MIT LICENCE
|
||||
*
|
||||
*/
|
||||
|
||||
var assert = require('assert'),
|
||||
path = require('path'),
|
||||
spawn = require('child_process').spawn,
|
||||
nssocket = require('nssocket'),
|
||||
forever = require('../../lib/forever'),
|
||||
Worker = require('../../lib/forever/worker').Worker;
|
||||
|
||||
var macros = exports;
|
||||
|
||||
macros.assertTimes = function (script, times, options) {
|
||||
options.max = times;
|
||||
|
||||
return {
|
||||
topic: function () {
|
||||
var child = new (forever.Monitor)(script, options);
|
||||
child.on('exit', this.callback.bind({}, null));
|
||||
child.start();
|
||||
},
|
||||
"should emit 'exit' when completed": function (err, child) {
|
||||
assert.equal(child.times, times);
|
||||
}
|
||||
};
|
||||
};
|
||||
|
||||
macros.spawn = function (args, options) {
|
||||
options.topic = function () {
|
||||
var self = this;
|
||||
|
||||
args = [path.join(__dirname, '..', 'bin', 'forever')].concat(args);
|
||||
|
||||
var child = spawn(process.argv[0], args),
|
||||
stdout = '',
|
||||
stderr = '';
|
||||
|
||||
child.stdout.on('data', function (data) {
|
||||
stdout += data;
|
||||
});
|
||||
child.stderr.on('data', function (data) {
|
||||
stderr += data;
|
||||
});
|
||||
child.once('exit', function (exitCode) {
|
||||
//
|
||||
// Remark: We wait 200 ms because of forever boot up time (master
|
||||
// doesn't wait for slave to start up after it's forked, it just quits)
|
||||
//
|
||||
setTimeout(function () {
|
||||
self.callback(null, exitCode, stdout, stderr);
|
||||
}, 200);
|
||||
});
|
||||
};
|
||||
return options;
|
||||
};
|
||||
|
||||
macros.list = function (options) {
|
||||
options.topic = function () {
|
||||
forever.list(false, this.callback);
|
||||
};
|
||||
return options;
|
||||
};
|
||||
|
||||
macros.assertStartsWith = function (string, substring) {
|
||||
assert.equal(string.slice(0, substring.length), substring);
|
||||
};
|
||||
|
||||
macros.assertList = function (list) {
|
||||
assert.isNotNull(list);
|
||||
assert.lengthOf(list, 1);
|
||||
};
|
||||
|
||||
macros.assertWorkerConnected = function (workerOptions, batch) {
|
||||
return {
|
||||
topic: function () {
|
||||
var self = this,
|
||||
reader = new nssocket.NsSocket(),
|
||||
worker = new Worker(workerOptions);
|
||||
|
||||
worker.start(function (err, sock) {
|
||||
reader.connect(sock, function () {
|
||||
self.callback(null, reader, worker, workerOptions);
|
||||
});
|
||||
});
|
||||
},
|
||||
'worker should connect': batch
|
||||
};
|
||||
};
|
||||
12
node_modules/forever/test/helpers/mocks/child-process.js
generated
vendored
Normal file
12
node_modules/forever/test/helpers/mocks/child-process.js
generated
vendored
Normal file
@@ -0,0 +1,12 @@
|
||||
var util = require('util'),
|
||||
EventEmitter2 = require('eventemitter2').EventEmitter2,
|
||||
StreamMock = require('./stream').StreamMock;
|
||||
|
||||
var ChildProcessMock = exports.ChildProcessMock = function () {
|
||||
EventEmitter2.call(this);
|
||||
|
||||
this.stdout = new StreamMock();
|
||||
this.stderr = new StreamMock();
|
||||
};
|
||||
util.inherits(ChildProcessMock, EventEmitter2);
|
||||
|
||||
25
node_modules/forever/test/helpers/mocks/monitor.js
generated
vendored
Normal file
25
node_modules/forever/test/helpers/mocks/monitor.js
generated
vendored
Normal file
@@ -0,0 +1,25 @@
|
||||
var util = require('util'),
|
||||
broadway = require('broadway'),
|
||||
ChildProcessMock = require('./child-process').ChildProcessMock;
|
||||
|
||||
var MonitorMock = exports.MonitorMock = function (options) {
|
||||
broadway.App.call(this, options);
|
||||
|
||||
this.child = new ChildProcessMock();
|
||||
this.running = false;
|
||||
};
|
||||
util.inherits(MonitorMock, broadway.App);
|
||||
|
||||
MonitorMock.prototype.__defineGetter__('data', function () {
|
||||
return {
|
||||
uid: '_uid',
|
||||
command: 'node'
|
||||
};
|
||||
});
|
||||
|
||||
MonitorMock.prototype.kill = MonitorMock.prototype.stop = function (forceStop) {
|
||||
this.running = false;
|
||||
|
||||
this.emit('stop');
|
||||
};
|
||||
|
||||
19
node_modules/forever/test/helpers/mocks/stream.js
generated
vendored
Normal file
19
node_modules/forever/test/helpers/mocks/stream.js
generated
vendored
Normal file
@@ -0,0 +1,19 @@
|
||||
var util = require('util'),
|
||||
EventEmitter2 = require('eventemitter2').EventEmitter2;
|
||||
|
||||
var StreamMock = exports.StreamMock = function () {
|
||||
EventEmitter2.call(this);
|
||||
|
||||
this.contents = [];
|
||||
this.closed = false;
|
||||
};
|
||||
util.inherits(StreamMock, EventEmitter2);
|
||||
|
||||
StreamMock.prototype.write = function (data) {
|
||||
this.contents.push(data);
|
||||
};
|
||||
|
||||
StreamMock.prototype.close = StreamMock.prototype.end = function () {
|
||||
this.closed = true;
|
||||
};
|
||||
|
||||
98
node_modules/forever/test/worker/multiple-workers-test.js
generated
vendored
Normal file
98
node_modules/forever/test/worker/multiple-workers-test.js
generated
vendored
Normal file
@@ -0,0 +1,98 @@
|
||||
/*
|
||||
* multiple-workers-test.js: Tests for spawning multiple workers with forever
|
||||
*
|
||||
* (C) 2010 Charlie Robbins & the Contributors
|
||||
* 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,
|
||||
args: [ "--port=8080"]
|
||||
});
|
||||
|
||||
children[1] = new (forever.Monitor)(script, {
|
||||
silent: true,
|
||||
maxRestart: 1,
|
||||
args: [ "--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);
|
||||
73
node_modules/forever/test/worker/simple-test.js
generated
vendored
Normal file
73
node_modules/forever/test/worker/simple-test.js
generated
vendored
Normal file
@@ -0,0 +1,73 @@
|
||||
var path = require('path'),
|
||||
assert = require('assert'),
|
||||
vows = require('vows'),
|
||||
nssocket = require('nssocket'),
|
||||
macros = require('../helpers/macros'),
|
||||
MonitorMock = require('../helpers/mocks/monitor').MonitorMock;
|
||||
|
||||
var SOCKET_PATH = path.join(__dirname, '..', 'fixtures');
|
||||
|
||||
vows.describe('forever/worker/simple').addBatch({
|
||||
'When using forever worker': {
|
||||
'and starting it and pinging it': macros.assertWorkerConnected({
|
||||
monitor: new MonitorMock(),
|
||||
sockPath: SOCKET_PATH
|
||||
}, {
|
||||
'and respond to pings': {
|
||||
topic: function (reader) {
|
||||
reader.send(['ping']);
|
||||
reader.data(['pong'], this.callback);
|
||||
},
|
||||
'with `pong`': function () {}
|
||||
},
|
||||
'and when queried for data': {
|
||||
topic: function (reader, _, options) {
|
||||
var self = this;
|
||||
|
||||
reader.send(['data']);
|
||||
reader.data(['data'], function (data) {
|
||||
self.callback(null, { data: data, monitor: options.monitor });
|
||||
});
|
||||
},
|
||||
'it should respond with data': function (obj) {
|
||||
assert.isObject(obj.data);
|
||||
assert.deepEqual(obj.data, obj.monitor.data);
|
||||
}
|
||||
},
|
||||
'and when asked to kill the process': {
|
||||
topic: function (reader, _, options) {
|
||||
var self = this;
|
||||
|
||||
options.monitor.running = true;
|
||||
reader.send(['stop']);
|
||||
reader.data(['stop', 'ok'], function () {
|
||||
self.callback(null, options.monitor);
|
||||
});
|
||||
},
|
||||
'it should kill the process': function (monitor) {
|
||||
assert.isFalse(monitor.running);
|
||||
}
|
||||
},
|
||||
'and when quickly sending data and disconnecting': {
|
||||
topic: function(reader) {
|
||||
var self = this;
|
||||
|
||||
// Need to connect second reader, otherwise it breaks the other
|
||||
// tests as the reader is shared with them.
|
||||
var reader2 = new nssocket.NsSocket();
|
||||
reader2.connect(reader.host, function() {
|
||||
reader2.send(['data']);
|
||||
reader2.destroy();
|
||||
|
||||
self.callback();
|
||||
});
|
||||
},
|
||||
'it should not crash the worker': function(worker) {
|
||||
// no asserition, everything is good if the test does not cause
|
||||
// a worker crash.
|
||||
}
|
||||
}
|
||||
})
|
||||
}
|
||||
}).export(module);
|
||||
|
||||
Reference in New Issue
Block a user