Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added graceful shutdown test

  • Loading branch information...
commit 42c40b9afb87e492fcfff54fae73f9cc48cacdc1 1 parent fe3eed7
@tj tj authored
View
27 test/master.js
@@ -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');
+});
View
1  test/pids/.gitignore
@@ -0,0 +1 @@
+*.pid
View
37 test/test.graceful-shutdown.js
@@ -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);
+});
Please sign in to comment.
Something went wrong with that request. Please try again.