summaryrefslogtreecommitdiff
path: root/test/parallel/test-cluster-fork-stdio.js
diff options
context:
space:
mode:
authorcjihrig <cjihrig@gmail.com>2016-07-22 12:05:27 -0400
committercjihrig <cjihrig@gmail.com>2016-08-01 15:08:42 -0400
commit75c6d9dd95bbdb926d84cb3a9f518eff88651709 (patch)
tree7d44b6f88a3027f1799d47115c344e871ac4dcf7 /test/parallel/test-cluster-fork-stdio.js
parent6d9a500064dc7e7df2491b1bed4555e8c53b4db2 (diff)
downloadnode-new-75c6d9dd95bbdb926d84cb3a9f518eff88651709.tar.gz
cluster: support stdio option for workers
This commit allows setupMaster() to configure the stdio channels for worker processes. Refs: https://github.com/nodejs/node-v0.x-archive/issues/5727 Refs: https://github.com/nodejs/node/pull/7811 PR-URL: https://github.com/nodejs/node/pull/7838 Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com>
Diffstat (limited to 'test/parallel/test-cluster-fork-stdio.js')
-rw-r--r--test/parallel/test-cluster-fork-stdio.js40
1 files changed, 40 insertions, 0 deletions
diff --git a/test/parallel/test-cluster-fork-stdio.js b/test/parallel/test-cluster-fork-stdio.js
new file mode 100644
index 0000000000..1d00e0768e
--- /dev/null
+++ b/test/parallel/test-cluster-fork-stdio.js
@@ -0,0 +1,40 @@
+'use strict';
+const common = require('../common');
+const assert = require('assert');
+const cluster = require('cluster');
+const net = require('net');
+
+if (cluster.isMaster) {
+ const buf = Buffer.from('foobar');
+
+ cluster.setupMaster({
+ stdio: ['pipe', 'pipe', 'pipe', 'ipc', 'pipe']
+ });
+
+ const worker = cluster.fork();
+ const channel = worker.process.stdio[4];
+ let response = '';
+
+ worker.on('exit', common.mustCall((code, signal) => {
+ assert.strictEqual(code, 0);
+ assert.strictEqual(signal, null);
+ }));
+
+ channel.setEncoding('utf8');
+ channel.on('data', (data) => {
+ response += data;
+
+ if (response === buf.toString()) {
+ worker.disconnect();
+ }
+ });
+ channel.write(buf);
+} else {
+ const pipe = new net.Socket({ fd: 4 });
+
+ pipe.unref();
+ pipe.on('data', (data) => {
+ assert.ok(data instanceof Buffer);
+ pipe.write(data);
+ });
+}