node/test/parallel/test-cluster-http-pipe.js
Adrian Estrada 9073fda52a test: refactor code in test-cluster-http-pipe
* use common.mustCall to control the functions execution automatically
* use const instead of var
* use assert.strictEqual instead assert.equal
* use assert.ifError instead of throw error

PR-URL: https://github.com/nodejs/node/pull/10297
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Minwoo Jung <jmwsoft@gmail.com>
Reviewed-By: Santiago Gimeno <santiago.gimeno@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
2016-12-22 22:22:07 -08:00

41 lines
1.0 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const http = require('http');
if (common.isWindows) {
common.skip('It is not possible to send pipe handles over ' +
'the IPC pipe on Windows');
return;
}
if (cluster.isMaster) {
common.refreshTmpDir();
const worker = cluster.fork();
worker.on('message', common.mustCall((msg) => {
assert.strictEqual(msg, 'DONE');
}));
worker.on('exit', common.mustCall(() => {}));
return;
}
http.createServer(common.mustCall((req, res) => {
assert.strictEqual(req.connection.remoteAddress, undefined);
assert.strictEqual(req.connection.localAddress, undefined);
// TODO common.PIPE?
res.writeHead(200);
res.end('OK');
})).listen(common.PIPE, common.mustCall(() => {
http.get({ socketPath: common.PIPE, path: '/' }, common.mustCall((res) => {
res.resume();
res.on('end', common.mustCall((err) => {
assert.ifError(err);
process.send('DONE');
process.exit();
}));
}));
}));