-
Notifications
You must be signed in to change notification settings - Fork 945
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
test cases for
stop<all|bypid> peaceful
- Loading branch information
Showing
3 changed files
with
156 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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(); | ||
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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,77 @@ | ||
/* | ||
* 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(); | ||
return proc; | ||
} | ||
|
||
vows.describe('forever/core/stopbypid-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 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); | ||
//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); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,2 @@ | ||
var cluster = require('cluster'); | ||
console.log(cluster.isMaster ? 'master fork':'cluster fork'); |