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

Refactored test-dgram-multicast-set-interface-lo.js by converting fun… #30536

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
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