Code coverage report for cluster-coverage/master.js

Statements: 88.24% (15 / 17)      Branches: 50% (1 / 2)      Functions: 100% (1 / 1)      Lines: 88.24% (15 / 17)      Ignored: none     

All files » cluster-coverage/ » master.js
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79                                1 1 1   1 1 1     1       1                       1                                                     1 1 1       1 1   1  
/**!
 * master process
 *
 * Copyright(c) fengmk2 and other contributors.
 * MIT Licensed
 *
 * Authors:
 *   fengmk2 <m@fengmk2.com> (http://fengmk2.com)
 */
 
'use strict';
 
/**
 * Module dependencies.
 */
 
const cluster = require('cluster');
const path = require('path');
const childprocess = require('child_process');
 
const workerPath = path.join(__dirname, 'worker.js');
const monitorPath = path.join(__dirname, 'monitor.js');
let monitor;
 
// setup cluster if running with istanbul coverage
Eif (process.env.running_under_istanbul) {
  // use coverage for forked process
  // disabled reporting and output for child process
  // enable pid in child process coverage filename
  cluster.setupMaster({
    exec: './node_modules/.bin/istanbul',
    args: [
      'cover',
      '--report', 'none',
      '--print', 'none',
      '--include-all-sources',
      '--include-pid',
      workerPath, '--'
    ]
  });
 
  monitor = childprocess.fork('./node_modules/.bin/istanbul', [
    'cover',
    '--report', 'none',
    '--print', 'none',
    '--include-all-sources',
    '--include-pid',
    monitorPath,
  ], {
    execArgv: process.execArgv.concat(['--debug-port=5856'])
  });
 
} else {
  cluster.setupMaster({
    exec: workerPath,
  });
 
  monitor = childprocess.fork(monitorPath, [], {
    // avoid monitor listen 5858 port
    // monitor: 5856
    // master: 5857
    // worker0: 5858
    // worker1: 5859
    // ...
    execArgv: process.execArgv.concat(['--debug-port=5856'])
  });
}
 
console.log('[master] new monitor:%s start', monitor.pid);
monitor.on('message', function (msg) {
  console.log('[master] got message %j', msg);
});
 
// fork two workers
cluster.fork();
cluster.fork();
 
exports.monitor = monitor;