From 20ee4997f31d4d86362b37a790505ecd86ef0572 Mon Sep 17 00:00:00 2001 From: Taylor Gagne Date: Mon, 18 Nov 2019 15:13:54 -0500 Subject: [PATCH] test: refactor test-dgram-multicast-set-interface-lo.js Convert functions to arrow functions. Remove unused param('signal') from function. PR-URL: https://github.com/nodejs/node/pull/30536 Reviewed-By: Rich Trott Reviewed-By: Anna Henningsen --- .../test-dgram-multicast-set-interface-lo.js | 33 ++++++++++--------- 1 file changed, 17 insertions(+), 16 deletions(-) diff --git a/test/internet/test-dgram-multicast-set-interface-lo.js b/test/internet/test-dgram-multicast-set-interface-lo.js index 73ab31884d5eb6..e06969b7b23673 100644 --- a/test/internet/test-dgram-multicast-set-interface-lo.js +++ b/test/internet/test-dgram-multicast-set-interface-lo.js @@ -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'); @@ -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) { @@ -138,7 +144,7 @@ if (process.argv[2] !== 'child') { } }); - worker.on('message', function(msg) { + worker.on('message', (msg) => { if (msg.listening) { listening += 1; @@ -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++; @@ -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) { @@ -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()), @@ -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') { @@ -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; @@ -280,7 +281,7 @@ if (process.argv[2] === 'child') { }); - listenSocket.on('listening', function() { + listenSocket.on('listening', () => { listenSocket.addMembership(MULTICAST, IFACE); process.send({ listening: true }); });