Skip to content

Commit

Permalink
test: refactor test-dgram-multicast-set-interface-lo.js
Browse files Browse the repository at this point in the history
Convert functions to arrow functions. Remove unused param('signal') from
function.

PR-URL: #30536
Reviewed-By: Rich Trott <[email protected]>
Reviewed-By: Anna Henningsen <[email protected]>
  • Loading branch information
Taylor Gagne authored and targos committed Dec 1, 2019
1 parent 18db451 commit 4441121
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions test/internet/test-dgram-multicast-set-interface-lo.js
Original file line number Diff line number Diff line change
Expand Up @@ -83,8 +83,14 @@ if (process.argv[2] !== 'child') {
let i = 0;
let done = 0;
let timer = null;

const killSubprocesses = (subprocesses) => {
for (const i in subprocesses)
subprocesses[i].kill();
};

// Exit the test if it doesn't succeed within the TIMEOUT.
timer = setTimeout(function() {
timer = setTimeout(() => {
console.error('[PARENT] Responses were not received within %d ms.',
TIMEOUT);
console.error('[PARENT] Skip');
Expand Down Expand Up @@ -115,7 +121,7 @@ if (process.argv[2] !== 'child') {
worker.messagesNeeded = messagesNeeded;

// Handle the death of workers.
worker.on('exit', function(code, signal) {
worker.on('exit', (code) => {
// Don't consider this a true death if the worker has finished
// successfully or if the exit code is 0.
if (worker.isDone || code === 0) {
Expand All @@ -138,7 +144,7 @@ if (process.argv[2] !== 'child') {
}
});

worker.on('message', function(msg) {
worker.on('message', (msg) => {
if (msg.listening) {
listening += 1;

Expand All @@ -162,12 +168,12 @@ if (process.argv[2] !== 'child') {
'required number of ' +
'messages. Will now compare.');

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

let count = 0;

worker.messagesReceived.forEach(function(buf) {
worker.messagesReceived.forEach((buf) => {
for (let i = 0; i < worker.messagesNeeded.length; ++i) {
if (buf.toString() === worker.messagesNeeded[i]) {
count++;
Expand Down Expand Up @@ -201,15 +207,15 @@ if (process.argv[2] !== 'child') {
// Don't bind the address explicitly when sending and start with
// the OSes default multicast interface selection.
sendSocket.bind(common.PORT, ANY[FAM]);
sendSocket.on('listening', function() {
sendSocket.on('listening', () => {
console.error(`outgoing iface ${interfaceAddress}`);
});

sendSocket.on('close', function() {
sendSocket.on('close', () => {
console.error('[PARENT] sendSocket closed');
});

sendSocket.sendNext = function() {
sendSocket.sendNext = () => {
const msg = messages[i++];

if (!msg) {
Expand All @@ -228,7 +234,7 @@ if (process.argv[2] !== 'child') {
buf.length,
PORTS[msg.mcast],
msg.mcast,
function(err) {
(err) => {
assert.ifError(err);
console.error('[PARENT] sent %s to %s:%s',
util.inspect(buf.toString()),
Expand All @@ -238,11 +244,6 @@ if (process.argv[2] !== 'child') {
}
);
};

function killSubprocesses(subprocesses) {
for (const i in subprocesses)
subprocesses[i].kill();
}
}

if (process.argv[2] === 'child') {
Expand All @@ -258,7 +259,7 @@ if (process.argv[2] === 'child') {
reuseAddr: true
});

listenSocket.on('message', function(buf, rinfo) {
listenSocket.on('message', (buf, rinfo) => {
// Examine udp messages only when they were sent by the parent.
if (!buf.toString().startsWith(SESSION)) return;

Expand All @@ -280,7 +281,7 @@ if (process.argv[2] === 'child') {
});


listenSocket.on('listening', function() {
listenSocket.on('listening', () => {
listenSocket.addMembership(MULTICAST, IFACE);
process.send({ listening: true });
});
Expand Down

0 comments on commit 4441121

Please sign in to comment.