Skip to content

Commit

Permalink
Added graceful shutdown test
Browse files Browse the repository at this point in the history
  • Loading branch information
tj committed Feb 14, 2011
1 parent fe3eed7 commit 42c40b9
Show file tree
Hide file tree
Showing 3 changed files with 65 additions and 0 deletions.
27 changes: 27 additions & 0 deletions test/master.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@

/**
* Module dependencies.
*/

var cluster = require('../')
, should = require('../support/should')
, http = require('http')
, fs = require('fs');

require('./common');

var server = http.createServer(function(req, res){
setTimeout(function(){
res.writeHead(200);
res.end('Hello World');
}, 1000);
});

cluster = cluster(server)
.set('workers', 2)
.use(cluster.pidfiles())
.listen(3000);

cluster.on('listening', function(){
console.log('listening');
});
1 change: 1 addition & 0 deletions test/pids/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.pid
37 changes: 37 additions & 0 deletions test/test.graceful-shutdown.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@

/**
* Module dependencies.
*/

var spawn = require('child_process').spawn
, should = require('should')
, http = require('http');

require('./common');

var calls = 0;

// child process

var child = spawn('node', [__dirname + '/master.js']);

// listening

child.stdout.on('data', function(chunk){
var options = { host: 'localhost', port: 3000 };

http.get(options, function(res){
++calls;
res.statusCode.should.equal(200);
child.kill('SIGQUIT');
});

http.get(options, function(res){
++calls;
res.statusCode.should.equal(200);
});
});

child.on('exit', function(){
calls.should.equal(2);
});

0 comments on commit 42c40b9

Please sign in to comment.