Permalink
Browse files

test: clean up dgram-broadcast-multi-process test

Use assert.strictEqual() instead of assert.equal(),
=== instead of ==, and const instead of var.

PR-URL: #9308
Reviewed-By: Rich Trott <rtrott@gmail.com>
Reviewed-By: Bryan English <bryan@bryanenglish.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
  • Loading branch information...
iredelmeier authored and Trott committed Oct 27, 2016
1 parent 6ef636c commit b9f6a2dc059a1062776133f3d4fd848c4da7d150
Showing with 24 additions and 19 deletions.
  1. +24 −19 test/internet/test-dgram-broadcast-multi-process.js
@@ -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;
}
}
@@ -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 = [];
@@ -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;
}
@@ -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;
@@ -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);
@@ -143,7 +148,7 @@ if (process.argv[2] !== 'child') {
})(x);
}
var sendSocket = dgram.createSocket({
const sendSocket = dgram.createSocket({
type: 'udp4',
reuseAddr: true
});
@@ -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) {}
@@ -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
});
@@ -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();
});

0 comments on commit b9f6a2d

Please sign in to comment.