test: clean up dgram-broadcast-multi-process test
Use assert.strictEqual() instead of assert.equal(), === instead of ==, and const instead of var. PR-URL: https://github.com/nodejs/node/pull/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>
This commit is contained in:
parent
6ef636c0c9
commit
b9f6a2dc05
@ -20,15 +20,17 @@ if (common.inFreeBSDJail) {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
let bindAddress = null;
|
||||||
|
|
||||||
// Take the first non-internal interface as the address for binding.
|
// 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
|
// Ideally, this should check for whether or not an interface is set up for
|
||||||
// BROADCAST and favor internal/private interfaces.
|
// BROADCAST and favor internal/private interfaces.
|
||||||
get_bindAddress: for (var name in networkInterfaces) {
|
get_bindAddress: for (const name in networkInterfaces) {
|
||||||
var interfaces = networkInterfaces[name];
|
const interfaces = networkInterfaces[name];
|
||||||
for (var i = 0; i < interfaces.length; i++) {
|
for (let i = 0; i < interfaces.length; i++) {
|
||||||
var localInterface = interfaces[i];
|
const localInterface = interfaces[i];
|
||||||
if (!localInterface.internal && localInterface.family === 'IPv4') {
|
if (!localInterface.internal && localInterface.family === 'IPv4') {
|
||||||
var bindAddress = localInterface.address;
|
bindAddress = localInterface.address;
|
||||||
break get_bindAddress;
|
break get_bindAddress;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@ -56,9 +58,9 @@ if (process.argv[2] !== 'child') {
|
|||||||
}, TIMEOUT);
|
}, TIMEOUT);
|
||||||
|
|
||||||
//launch child processes
|
//launch child processes
|
||||||
for (var x = 0; x < listeners; x++) {
|
for (let x = 0; x < listeners; x++) {
|
||||||
(function() {
|
(function() {
|
||||||
var worker = fork(process.argv[1], ['child']);
|
const worker = fork(process.argv[1], ['child']);
|
||||||
workers[worker.pid] = worker;
|
workers[worker.pid] = worker;
|
||||||
|
|
||||||
worker.messagesReceived = [];
|
worker.messagesReceived = [];
|
||||||
@ -68,7 +70,7 @@ if (process.argv[2] !== 'child') {
|
|||||||
// don't consider this the true death if the worker
|
// don't consider this the true death if the worker
|
||||||
// has finished successfully
|
// has finished successfully
|
||||||
// or if the exit code is 0
|
// or if the exit code is 0
|
||||||
if (worker.isDone || code == 0) {
|
if (worker.isDone || code === 0) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -113,12 +115,12 @@ if (process.argv[2] !== 'child') {
|
|||||||
'messages. Will now compare.');
|
'messages. Will now compare.');
|
||||||
|
|
||||||
Object.keys(workers).forEach(function(pid) {
|
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) {
|
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()) {
|
if (buf.toString() === messages[i].toString()) {
|
||||||
count++;
|
count++;
|
||||||
break;
|
break;
|
||||||
@ -130,8 +132,11 @@ if (process.argv[2] !== 'child') {
|
|||||||
worker.pid,
|
worker.pid,
|
||||||
count);
|
count);
|
||||||
|
|
||||||
assert.equal(count, messages.length,
|
assert.strictEqual(
|
||||||
'A worker received an invalid multicast message');
|
count,
|
||||||
|
messages.length,
|
||||||
|
'A worker received an invalid multicast message'
|
||||||
|
);
|
||||||
});
|
});
|
||||||
|
|
||||||
clearTimeout(timer);
|
clearTimeout(timer);
|
||||||
@ -143,7 +148,7 @@ if (process.argv[2] !== 'child') {
|
|||||||
})(x);
|
})(x);
|
||||||
}
|
}
|
||||||
|
|
||||||
var sendSocket = dgram.createSocket({
|
const sendSocket = dgram.createSocket({
|
||||||
type: 'udp4',
|
type: 'udp4',
|
||||||
reuseAddr: true
|
reuseAddr: true
|
||||||
});
|
});
|
||||||
@ -160,7 +165,7 @@ if (process.argv[2] !== 'child') {
|
|||||||
});
|
});
|
||||||
|
|
||||||
sendSocket.sendNext = function() {
|
sendSocket.sendNext = function() {
|
||||||
var buf = messages[i++];
|
const buf = messages[i++];
|
||||||
|
|
||||||
if (!buf) {
|
if (!buf) {
|
||||||
try { sendSocket.close(); } catch (e) {}
|
try { sendSocket.close(); } catch (e) {}
|
||||||
@ -186,15 +191,15 @@ if (process.argv[2] !== 'child') {
|
|||||||
|
|
||||||
function killChildren(children) {
|
function killChildren(children) {
|
||||||
Object.keys(children).forEach(function(key) {
|
Object.keys(children).forEach(function(key) {
|
||||||
var child = children[key];
|
const child = children[key];
|
||||||
child.kill();
|
child.kill();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (process.argv[2] === 'child') {
|
if (process.argv[2] === 'child') {
|
||||||
var receivedMessages = [];
|
const receivedMessages = [];
|
||||||
var listenSocket = dgram.createSocket({
|
const listenSocket = dgram.createSocket({
|
||||||
type: 'udp4',
|
type: 'udp4',
|
||||||
reuseAddr: true
|
reuseAddr: true
|
||||||
});
|
});
|
||||||
@ -212,7 +217,7 @@ if (process.argv[2] === 'child') {
|
|||||||
|
|
||||||
process.send({message: buf.toString()});
|
process.send({message: buf.toString()});
|
||||||
|
|
||||||
if (receivedMessages.length == messages.length) {
|
if (receivedMessages.length === messages.length) {
|
||||||
process.nextTick(function() {
|
process.nextTick(function() {
|
||||||
listenSocket.close();
|
listenSocket.close();
|
||||||
});
|
});
|
||||||
|
Loading…
x
Reference in New Issue
Block a user