test.worker-term.js 736 B

12345678910111213141516171819202122232425262728293031323334353637
  1. /**
  2. * Module dependencies.
  3. */
  4. var cluster = require('../')
  5. , http = require('http');
  6. require('./common');
  7. var server = http.createServer(function(req, res){
  8. res.writeHead(200);
  9. res.end('Hello World');
  10. });
  11. cluster = cluster(server)
  12. .set('workers', 1)
  13. .listen(3000);
  14. cluster.on('listening', function(){
  15. http.get({ host: 'localhost', port: 3000 }, function(res){
  16. res.statusCode.should.equal(200);
  17. // kill the worker
  18. var pid = cluster.children[0].proc.pid;
  19. process.kill(pid, 'SIGTERM');
  20. });
  21. });
  22. cluster.on('worker killed', function(worker){
  23. worker.id.should.equal(0);
  24. http.get({ host: 'localhost', port: 3000 }, function(res){
  25. res.statusCode.should.equal(200);
  26. cluster.close();
  27. });
  28. });