Skip to content
This repository
Browse code

Added worker SIGQUIT keep-alive test

  • Loading branch information...
commit 864f46b1d5a07c18be27ed3d7e8ff2f11503bc36 1 parent d4c8823
TJ Holowaychuk authored February 21, 2011
14  test/common.js
@@ -8,9 +8,11 @@ var http = require('http')
8 8
 
9 9
 // COMPAT:
10 10
 
11  
-http.get = function(options, fn){
12  
-  var client = http.createClient(options.port, options.host)
13  
-    , req = client.request('GET', options.path || '/');
14  
-  req.on('response', fn).end();
15  
-  return req;
16  
-};
  11
+if (!http.get) {
  12
+  http.get = function(options, fn){
  13
+    var client = http.createClient(options.port, options.host)
  14
+      , req = client.request('GET', options.path || '/');
  15
+    req.on('response', fn).end();
  16
+    return req;
  17
+  };
  18
+}
56  test/test.worker-quit-keep-alive.js
... ...
@@ -0,0 +1,56 @@
  1
+
  2
+/**
  3
+ * Module dependencies.
  4
+ */
  5
+
  6
+var cluster = require('../')
  7
+  , http = require('http');
  8
+
  9
+require('./common');
  10
+
  11
+var server = http.createServer(function(req, res){
  12
+  res.writeHead(200);
  13
+  res.end('Hello World');
  14
+});
  15
+
  16
+// request options
  17
+
  18
+var options = {
  19
+    host: 'localhost'
  20
+  , port: 3000
  21
+  , headers: { Connection: 'keep-alive' }
  22
+};
  23
+
  24
+// cluster
  25
+
  26
+cluster = cluster(server)
  27
+  .set('workers', 1)
  28
+  .set('timeout', 1000)
  29
+  .listen(3000);
  30
+
  31
+cluster.on('listening', function(){
  32
+  http.get(options, function(res){
  33
+    res.statusCode.should.equal(200);
  34
+
  35
+    // kill the worker
  36
+    var pid = cluster.children[0].proc.pid;
  37
+    process.kill(pid, 'SIGQUIT');
  38
+  });
  39
+});
  40
+
  41
+var timeout;
  42
+
  43
+cluster.on('worker timeout', function(worker){
  44
+  worker.id.should.equal(0);
  45
+  timeout = true;
  46
+});
  47
+
  48
+cluster.on('worker connected', function(worker){
  49
+  if (timeout) {
  50
+    worker.id.should.equal(0);
  51
+    http.get(options, function(res){
  52
+      res.statusCode.should.equal(200);
  53
+      cluster.close();
  54
+    });
  55
+  }
  56
+});

0 notes on commit 864f46b

Please sign in to comment.
Something went wrong with that request. Please try again.