Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixed restart pidfile comparison tests

  • Loading branch information...
commit cf40e85c7462ef61efa4d56416adbe8166c9695a 1 parent 44d0a33
@tj tj authored
Showing with 25 additions and 17 deletions.
  1. +8 −3 lib/plugins/pidfiles.js
  2. +17 −14 test/test.restart.js
View
11 lib/plugins/pidfiles.js
@@ -42,7 +42,6 @@ module.exports = function(dir){
dir = master.pidfiles = master.resolve(dir || 'pids');
mkdir(dir, 0755, function(err){
if (err) throw err;
- function fn(err){ if (err) throw err; }
// augment master
master.pidof = function(name){
@@ -65,12 +64,18 @@ module.exports = function(dir){
// save worker pids
master.on('worker', function(worker){
var path = dir + '/worker.' + worker.id + '.pid';
- fs.writeFile(path, worker.proc.pid.toString(), 'ascii', fn);
+ fs.writeFile(path, worker.proc.pid.toString(), 'ascii', function(err){
+ if (err) throw err;
+ master.emit('worker pidfile');
+ });
});
master.on('listening', function(){
// save master pid
- fs.writeFile(dir + '/master.pid', process.pid.toString(), 'ascii', fn);
+ fs.writeFile(dir + '/master.pid', process.pid.toString(), 'ascii', function(err){
+ if (err) throw err;
+ master.emit('pidfile');
+ });
});
});
}
View
31 test/test.restart.js
@@ -39,25 +39,28 @@ if (cluster.isChild) {
http.get(options, function(res){
res.statusCode.should.equal(200);
var a = getPID('old.worker.0.pid')
- , b = getPID('old.worker.1.pid');
+ , b = getPID('old.worker.1.pid');
a.should.not.equal(getPID('worker.0.pid'));
b.should.not.equal(getPID('worker.1.pid'));
cluster.close();
});
});
} else {
- cluster.on('listening', function(){
- movePID('worker.0.pid')
- movePID('worker.1.pid');
-
- // issue some requests
- var n = 20
- , pending = n;
- while (n--) {
- http.get(options, function(res){
- res.statusCode.should.equal(200);
- --pending || cluster.restart();
- });
- }
+ var pending = 2;
+ cluster.on('worker pidfile', function(){
+ --pending || (function(){
+ movePID('worker.0.pid')
+ movePID('worker.1.pid');
+
+ // issue some requests
+ var n = 20
+ , pending = n;
+ while (n--) {
+ http.get(options, function(res){
+ res.statusCode.should.equal(200);
+ --pending || cluster.restart();
+ });
+ }
+ })();
});
}
Please sign in to comment.
Something went wrong with that request. Please try again.