mirror of
https://github.com/nodejs/node.git
synced 2025-05-05 19:08:17 +00:00

Many of the tests use variables to track when callback functions are invoked or events are emitted. These variables are then asserted on process exit. This commit replaces this pattern in straightforward cases with common.mustCall(). This makes the tests easier to reason about, leads to a net reduction in lines of code, and uncovered a few bugs in tests. This commit also replaces some callbacks that should never be called with common.fail(). PR-URL: https://github.com/nodejs/node/pull/7753 Reviewed-By: Wyatt Preul <wpreul@gmail.com> Reviewed-By: Minwoo Jung <jmwsoft@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
41 lines
1003 B
JavaScript
41 lines
1003 B
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();
|
|
var worker = cluster.fork();
|
|
worker.on('message', common.mustCall(function(msg) {
|
|
assert.equal(msg, 'DONE');
|
|
}));
|
|
worker.on('exit', function() {
|
|
process.exit();
|
|
});
|
|
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() {
|
|
http.get({ socketPath: common.PIPE, path: '/' }, function(res) {
|
|
res.resume();
|
|
res.on('end', function(err) {
|
|
if (err) throw err;
|
|
process.send('DONE');
|
|
process.exit();
|
|
});
|
|
});
|
|
});
|