• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3const assert = require('assert');
4const cluster = require('cluster');
5const net = require('net');
6
7if (cluster.isMaster) {
8  const buf = Buffer.from('foobar');
9
10  cluster.setupMaster({
11    stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'pipe']
12  });
13
14  const worker = cluster.fork();
15  const channel = worker.process.stdio[4];
16  let response = '';
17
18  worker.on('exit', common.mustCall((code, signal) => {
19    assert.strictEqual(code, 0);
20    assert.strictEqual(signal, null);
21  }));
22
23  channel.setEncoding('utf8');
24  channel.on('data', (data) => {
25    response += data;
26
27    if (response === buf.toString()) {
28      worker.disconnect();
29    }
30  });
31  channel.write(buf);
32} else {
33  const pipe = new net.Socket({ fd: 4 });
34
35  pipe.unref();
36  pipe.on('data', (data) => {
37    assert.ok(data instanceof Buffer);
38    pipe.write(data);
39  });
40}
41