Skip to content

Commit

Permalink
test: refactor test-cluster-send-handle-twice.js
Browse files Browse the repository at this point in the history
- `var` --> `const` as applicable
- `assert.equal`  --> `assert.strictEqual`
- `assert(false, ..)` --> `common.fail()`
- `common.mustCall` for functions that need to be called exactly once
- modified an `assert(!signal, 'Worker exited by a signal');` call to
  `assert.strictEqual(signal, null);` call as that made more sense

PR-URL: #10049
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
  • Loading branch information
amarzavery authored and targos committed Dec 26, 2016
1 parent aba15fb commit f9f2cda
Showing 1 changed file with 14 additions and 14 deletions.
28 changes: 14 additions & 14 deletions test/parallel/test-cluster-send-handle-twice.js
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
'use strict';
// Testing to send an handle twice to the parent process.

var common = require('../common');
var assert = require('assert');
var cluster = require('cluster');
var net = require('net');
const common = require('../common');
const assert = require('assert');
const cluster = require('cluster');
const net = require('net');

var workers = {
const workers = {
toStart: 1
};

if (cluster.isMaster) {
for (var i = 0; i < workers.toStart; ++i) {
var worker = cluster.fork();
worker.on('exit', function(code, signal) {
for (let i = 0; i < workers.toStart; ++i) {
const worker = cluster.fork();
worker.on('exit', common.mustCall(function(code, signal) {
assert.strictEqual(code, 0, 'Worker exited with an error code');
assert(!signal, 'Worker exited by a signal');
});
assert.strictEqual(signal, null, 'Worker exited by a signal');
}));
}
} else {
var server = net.createServer(function(socket) {
const server = net.createServer(function(socket) {
process.send('send-handle-1', socket);
process.send('send-handle-2', socket);
});

server.listen(common.PORT, function() {
var client = net.connect({ host: 'localhost', port: common.PORT });
client.on('close', function() { cluster.worker.disconnect(); });
const client = net.connect({ host: 'localhost', port: common.PORT });
client.on('close', common.mustCall(() => { cluster.worker.disconnect(); }));
setTimeout(function() { client.end(); }, 50);
}).on('error', function(e) {
console.error(e);
assert(false, 'server.listen failed');
common.fail('server.listen failed');
cluster.worker.disconnect();
});
}

0 comments on commit f9f2cda

Please sign in to comment.