Skip to content

Commit

Permalink
test: clean up dgram-broadcast-multi-process test
Browse files Browse the repository at this point in the history
Use assert.strictEqual() instead of assert.equal(),
=== instead of ==, and const instead of var.

PR-URL: #9308
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Bryan English <[email protected]>
Reviewed-By: Colin Ihrig <[email protected]>
Reviewed-By: James M Snell <[email protected]>
  • Loading branch information
iredelmeier authored and Myles Borins committed Nov 22, 2016
1 parent ce05b70 commit bec1cca
Showing 1 changed file with 24 additions and 19 deletions.
43 changes: 24 additions & 19 deletions test/internet/test-dgram-broadcast-multi-process.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,17 @@ if (common.inFreeBSDJail) {
return;
}

let bindAddress = null;

// Take the first non-internal interface as the address for binding.
// Ideally, this should check for whether or not an interface is set up for
// BROADCAST and favor internal/private interfaces.
get_bindAddress: for (var name in networkInterfaces) {
var interfaces = networkInterfaces[name];
for (var i = 0; i < interfaces.length; i++) {
var localInterface = interfaces[i];
get_bindAddress: for (const name in networkInterfaces) {
const interfaces = networkInterfaces[name];
for (let i = 0; i < interfaces.length; i++) {
const localInterface = interfaces[i];
if (!localInterface.internal && localInterface.family === 'IPv4') {
var bindAddress = localInterface.address;
bindAddress = localInterface.address;
break get_bindAddress;
}
}
Expand Down Expand Up @@ -56,9 +58,9 @@ if (process.argv[2] !== 'child') {
}, TIMEOUT);

//launch child processes
for (var x = 0; x < listeners; x++) {
for (let x = 0; x < listeners; x++) {
(function() {
var worker = fork(process.argv[1], ['child']);
const worker = fork(process.argv[1], ['child']);
workers[worker.pid] = worker;

worker.messagesReceived = [];
Expand All @@ -68,7 +70,7 @@ if (process.argv[2] !== 'child') {
// don't consider this the true death if the worker
// has finished successfully
// or if the exit code is 0
if (worker.isDone || code == 0) {
if (worker.isDone || code === 0) {
return;
}

Expand Down Expand Up @@ -113,12 +115,12 @@ if (process.argv[2] !== 'child') {
'messages. Will now compare.');

Object.keys(workers).forEach(function(pid) {
var worker = workers[pid];
const worker = workers[pid];

var count = 0;
let count = 0;

worker.messagesReceived.forEach(function(buf) {
for (var i = 0; i < messages.length; ++i) {
for (let i = 0; i < messages.length; ++i) {
if (buf.toString() === messages[i].toString()) {
count++;
break;
Expand All @@ -130,8 +132,11 @@ if (process.argv[2] !== 'child') {
worker.pid,
count);

assert.equal(count, messages.length,
'A worker received an invalid multicast message');
assert.strictEqual(
count,
messages.length,
'A worker received an invalid multicast message'
);
});

clearTimeout(timer);
Expand All @@ -143,7 +148,7 @@ if (process.argv[2] !== 'child') {
})(x);
}

var sendSocket = dgram.createSocket({
const sendSocket = dgram.createSocket({
type: 'udp4',
reuseAddr: true
});
Expand All @@ -160,7 +165,7 @@ if (process.argv[2] !== 'child') {
});

sendSocket.sendNext = function() {
var buf = messages[i++];
const buf = messages[i++];

if (!buf) {
try { sendSocket.close(); } catch (e) {}
Expand All @@ -186,15 +191,15 @@ if (process.argv[2] !== 'child') {

function killChildren(children) {
Object.keys(children).forEach(function(key) {
var child = children[key];
const child = children[key];
child.kill();
});
}
}

if (process.argv[2] === 'child') {
var receivedMessages = [];
var listenSocket = dgram.createSocket({
const receivedMessages = [];
const listenSocket = dgram.createSocket({
type: 'udp4',
reuseAddr: true
});
Expand All @@ -212,7 +217,7 @@ if (process.argv[2] === 'child') {

process.send({message: buf.toString()});

if (receivedMessages.length == messages.length) {
if (receivedMessages.length === messages.length) {
process.nextTick(function() {
listenSocket.close();
});
Expand Down

0 comments on commit bec1cca

Please sign in to comment.