Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
wants to merge 1 commit into from
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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