node/test/parallel/test-cluster-http-pipe.js
Rich Trott 7c79490bfb test: only refresh tmpDir for tests that need it
Expose `common.refreshTmpDir()` and only call it
for tests that use common.tmpDir or common.PIPE.

A positive side effect is the removal of a code
smell where child processes were detected by the
presence of `.send()`. Now each process can decide
for itself if it needs to refresh tmpDir.

PR-URL: https://github.com/nodejs/io.js/pull/1954
Reviewed-By: Rod Vagg <rod@vagg.org>
Reviewed-By: Johan Bergström <bugs@bergstroem.nu>
2015-06-13 22:27:17 -07:00

45 lines
1.0 KiB
JavaScript

'use strict';
// It is not possible to send pipe handles over the IPC pipe on Windows.
if (process.platform === 'win32') {
process.exit(0);
}
var common = require('../common');
var assert = require('assert');
var cluster = require('cluster');
var http = require('http');
if (cluster.isMaster) {
common.refreshTmpDir();
var ok = false;
var worker = cluster.fork();
worker.on('message', function(msg) {
assert.equal(msg, 'DONE');
ok = true;
});
worker.on('exit', function() {
process.exit();
});
process.on('exit', function() {
assert(ok);
});
return;
}
http.createServer(function(req, res) {
assert.equal(req.connection.remoteAddress, undefined);
assert.equal(req.connection.localAddress, undefined); // TODO common.PIPE?
res.writeHead(200);
res.end('OK');
}).listen(common.PIPE, function() {
var self = this;
http.get({ socketPath: common.PIPE, path: '/' }, function(res) {
res.resume();
res.on('end', function(err) {
if (err) throw err;
process.send('DONE');
process.exit();
});
});
});