Browse Source

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>
v6
Adrian Estrada 8 years ago
committed by James M Snell
parent
commit
9073fda52a
  1. 32
      test/parallel/test-cluster-http-pipe.js

32
test/parallel/test-cluster-http-pipe.js

@ -13,28 +13,28 @@ if (common.isWindows) {
if (cluster.isMaster) { if (cluster.isMaster) {
common.refreshTmpDir(); common.refreshTmpDir();
var worker = cluster.fork(); const worker = cluster.fork();
worker.on('message', common.mustCall(function(msg) { worker.on('message', common.mustCall((msg) => {
assert.equal(msg, 'DONE'); assert.strictEqual(msg, 'DONE');
})); }));
worker.on('exit', function() { worker.on('exit', common.mustCall(() => {}));
process.exit();
});
return; return;
} }
http.createServer(function(req, res) { http.createServer(common.mustCall((req, res) => {
assert.equal(req.connection.remoteAddress, undefined); assert.strictEqual(req.connection.remoteAddress, undefined);
assert.equal(req.connection.localAddress, undefined); // TODO common.PIPE? assert.strictEqual(req.connection.localAddress, undefined);
// TODO common.PIPE?
res.writeHead(200); res.writeHead(200);
res.end('OK'); res.end('OK');
}).listen(common.PIPE, function() { })).listen(common.PIPE, common.mustCall(() => {
http.get({ socketPath: common.PIPE, path: '/' }, function(res) { http.get({ socketPath: common.PIPE, path: '/' }, common.mustCall((res) => {
res.resume(); res.resume();
res.on('end', function(err) { res.on('end', common.mustCall((err) => {
if (err) throw err; assert.ifError(err);
process.send('DONE'); process.send('DONE');
process.exit(); process.exit();
}); }));
}); }));
}); }));

Loading…
Cancel
Save