Permalink
Browse files

[dist api test refactor] Finished refactor of core programmatic APIs …

…and tests from `forever`
  • Loading branch information...
1 parent a8e6920 commit 7b4d637bf6d5c72101278a3790a2ef166ba91162 @indexzero indexzero committed Jul 6, 2012
View
@@ -0,0 +1 @@
+console.log(JSON.stringify(process.env));
View
@@ -0,0 +1 @@
+throw new Error('Dont spin restart')
@@ -0,0 +1,4 @@
+forever start examples/server.js -p 8080
+forever start examples/server.js -p 8081
+forever start examples/server.js -p 8082
+forever list
View
@@ -0,0 +1,8 @@
+var util = require('util');
+
+var count = 0;
+
+var id = setInterval(function () {
+ util.puts('Count is ' + count + '. Incrementing now.');
+ count++;
+}, 1000);
View
@@ -0,0 +1 @@
+console.log(process.cwd());
View
@@ -0,0 +1,7 @@
+var http = require('http');
+
+http.createServer(function (req, res) {
+ res.writeHead(200, { 'Content-Type': 'application/json' });
+ res.write(JSON.stringify(process.env));
+ res.end();
+}).listen(8080);
View
@@ -0,0 +1,4 @@
+console.log(JSON.stringify({
+ foo: process.env.FOO,
+ bar: process.env.BAR
+}));
@@ -0,0 +1,6 @@
+var util = require('util');
+
+setTimeout(function () {
+ util.puts('Throwing error now.');
+ throw new Error('User generated fault.');
+}, 200);
View
@@ -0,0 +1,37 @@
+var path = require('path'),
+ async = require('utile').async,
+ forever = require('../lib/forever');
+
+function startServer (port, next) {
+ var child = new (forever.Monitor) (script, {
+ options: [ '--port', port],
+ silent: true
+ });
+
+ child.start();
+ child.on('start', function (_, data) {
+ console.log('Forever process running server.js on ' + port);
+ next(null, child);
+ });
+}
+
+// Array config data
+var script = path.join(__dirname, 'server.js'),
+ ports = [8080, 8081, 8082];
+
+async.map(ports, startServer, function (err, monitors) {
+ forever.startServer(monitors, function () {
+ //
+ // Now that the server has started, run `forever.list()`
+ //
+ forever.list(false, function (err, data) {
+ if (err) {
+ console.log('Error running `forever.list()`');
+ console.dir(err);
+ }
+
+ console.log('Data returned from `forever.list()`');
+ console.dir(data)
+ })
+ });
+});
@@ -0,0 +1,3 @@
+setInterval(function () {
+ console.log('Logging at ' + Date.now());
+}, 100);
@@ -0,0 +1,12 @@
+var util = require('util'),
+ path = require('path'),
+ forever = require('./../lib/forever'),
+ script = path.join(__dirname, 'server.js');
+
+var child1 = new (forever.Monitor)(script, { 'options': [ "--port=8080"] });
+child1.start();
+util.puts('Forever process running server.js on 8080');
+
+var child2 = new (forever.Monitor)(script, { 'options': [ "--port=8081"] });
+child2.start();
+util.puts('Forever process running server.js on 8081');
View
@@ -0,0 +1,6 @@
+
+setInterval(function () {
+ if (process.send) {
+ process.send({ from: 'child' });
+ }
+}, 1000)
View
@@ -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);
+
@@ -0,0 +1,8 @@
+function noop() {
+ console.log('IGNORED!')
+}
+process.on('SIGTERM',noop);
+process.on('SIGINT',noop);
+setInterval(function(){
+ console.log('heartbeat');
+}, 100);
@@ -0,0 +1,18 @@
+var util = require('util'),
+ path = require('path'),
+ spawn = require('child_process').spawn;
+
+var child = spawn('node', [path.join(__dirname, 'count-timer.js')], { cwd: __dirname });
+
+child.stdout.on('data', function (data) {
+ util.puts(data);
+ //throw new Error('User generated fault.');
+});
+
+child.stderr.on('data', function (data) {
+ util.puts(data);
+});
+
+child.on('exit', function (code) {
+ util.puts('Child process exited with code: ' + code);
+});
@@ -13,7 +13,6 @@ var events = require('events'),
spawn = child_process.spawn,
broadway = require('broadway'),
psTree = require('ps-tree'),
- winston = require('winston'),
utile = require('utile'),
common = require('./common'),
plugins = require('./plugins');
@@ -157,20 +156,17 @@ Monitor.prototype.start = function (restart) {
child.on('exit', function (code) {
var spinning = Date.now() - self.ctime < self.minUptime;
- self.warn('Forever detected script exited with code: ' + code);
child.removeListener('message', onMessage);
function letChildDie() {
self.running = false;
self.forceStop = false;
-
self.emit('exit', self, spinning);
}
function restartChild() {
self.forceRestart = false;
process.nextTick(function () {
- self.warn('Forever restarting script for ' + self.times + ' time');
self.start(true);
});
}
@@ -200,7 +196,7 @@ Monitor.prototype.start = function (restart) {
// trying to execute a script with an env: e.g. node myfile.js
//
Monitor.prototype.trySpawn = function () {
- if (this.command === 'node' && this.checkFile && !this.childExists) {
+ if (/node/.test(this.command) && this.checkFile && !this.childExists) {
try {
var stats = fs.statSync(this.args[0]);
this.childExists = true;
View
@@ -1,6 +1,8 @@
var utile = require('utile');
+exports.checkProcess = require('./forever-monitor/common').checkProcess;
+exports.kill = require('./forever-monitor/common').kill;
exports.Monitor = require('./forever-monitor/monitor').Monitor;
//
View
@@ -22,18 +22,14 @@
"tools"
],
"dependencies": {
- "broadway": "0.1.x",
+ "broadway": "0.2.x",
"minimatch": "0.0.x",
"pkginfo": "0.x.x",
"ps-tree": "0.0.x",
- "timespan": "2.0.x",
"watch": "0.5.x",
- "utile": "0.0.x",
- "winston": "0.6.x"
+ "utile": "0.0.x"
},
"devDependencies": {
- "eventemitter2": "0.4.x",
- "request": "2.x.x",
"vows": "0.6.x"
},
"main": "./lib/index.js",
@@ -0,0 +1,36 @@
+/*
+ * check-process-test.js: Tests for forever.checkProcess(pid)
+ *
+ * (C) 2010 Nodejitsu Inc.
+ * MIT LICENCE
+ *
+ */
+
+var assert = require('assert'),
+ path = require('path'),
+ vows = require('vows'),
+ fmonitor = require('../../lib');
+
+vows.describe('forever/core/check-process').addBatch({
+ "When using forever": {
+ "checking if process exists": {
+ "if process exists": {
+ topic: fmonitor.checkProcess(process.pid),
+ "should return true": function (result) {
+ assert.isTrue(result);
+ }
+ },
+ "if process doesn't exist": {
+ topic: fmonitor.checkProcess(255 * 255 * 255),
+ //
+ // This is insanely large value. On most systems there'll be no process
+ // with such PID. Also, there's no multiplatform way to check for
+ // PID limit.
+ //
+ "should return false": function (result) {
+ assert.isFalse(result);
+ }
+ }
+ }
+ }
+}).export(module);
View
@@ -0,0 +1,5 @@
+
+for (var i = 0; i < 10; i++) {
+ console.log('stdout %d', i);
+ console.error('stderr %d', i);
+}
@@ -0,0 +1,2 @@
+node_modules
+ignore*
@@ -0,0 +1,3 @@
+console.log('Hello!');
+setTimeout(process.exit, 2000);
+
View
@@ -0,0 +1 @@
+/* hello, I know nodejitsu. */
No changes.
@@ -12,7 +12,7 @@ var assert = require('assert'),
vows = require('vows'),
fmonitor = require('../../lib');
-vows.describe('forever-monitor/monitor/watch').addBatch({
+vows.describe('forever-monitor/plugins/watch').addBatch({
'When using forever with watch enabled': {
'forever should': {
topic: fmonitor.start('daemon.js', {

0 comments on commit 7b4d637

Please sign in to comment.