Skip to content

Commit b9f6a2d

Browse files
iredelmeierTrott
authored andcommitted
test: clean up dgram-broadcast-multi-process test
Use assert.strictEqual() instead of assert.equal(), === instead of ==, and const instead of var. PR-URL: #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>
1 parent 6ef636c commit b9f6a2d

File tree

1 file changed

+24
-19
lines changed

1 file changed

+24
-19
lines changed

test/internet/test-dgram-broadcast-multi-process.js

+24-19
Original file line numberDiff line numberDiff line change
@@ -20,15 +20,17 @@ if (common.inFreeBSDJail) {
2020
return;
2121
}
2222

23+
let bindAddress = null;
24+
2325
// Take the first non-internal interface as the address for binding.
2426
// Ideally, this should check for whether or not an interface is set up for
2527
// BROADCAST and favor internal/private interfaces.
26-
get_bindAddress: for (var name in networkInterfaces) {
27-
var interfaces = networkInterfaces[name];
28-
for (var i = 0; i < interfaces.length; i++) {
29-
var localInterface = interfaces[i];
28+
get_bindAddress: for (const name in networkInterfaces) {
29+
const interfaces = networkInterfaces[name];
30+
for (let i = 0; i < interfaces.length; i++) {
31+
const localInterface = interfaces[i];
3032
if (!localInterface.internal && localInterface.family === 'IPv4') {
31-
var bindAddress = localInterface.address;
33+
bindAddress = localInterface.address;
3234
break get_bindAddress;
3335
}
3436
}
@@ -56,9 +58,9 @@ if (process.argv[2] !== 'child') {
5658
}, TIMEOUT);
5759

5860
//launch child processes
59-
for (var x = 0; x < listeners; x++) {
61+
for (let x = 0; x < listeners; x++) {
6062
(function() {
61-
var worker = fork(process.argv[1], ['child']);
63+
const worker = fork(process.argv[1], ['child']);
6264
workers[worker.pid] = worker;
6365

6466
worker.messagesReceived = [];
@@ -68,7 +70,7 @@ if (process.argv[2] !== 'child') {
6870
// don't consider this the true death if the worker
6971
// has finished successfully
7072
// or if the exit code is 0
71-
if (worker.isDone || code == 0) {
73+
if (worker.isDone || code === 0) {
7274
return;
7375
}
7476

@@ -113,12 +115,12 @@ if (process.argv[2] !== 'child') {
113115
'messages. Will now compare.');
114116

115117
Object.keys(workers).forEach(function(pid) {
116-
var worker = workers[pid];
118+
const worker = workers[pid];
117119

118-
var count = 0;
120+
let count = 0;
119121

120122
worker.messagesReceived.forEach(function(buf) {
121-
for (var i = 0; i < messages.length; ++i) {
123+
for (let i = 0; i < messages.length; ++i) {
122124
if (buf.toString() === messages[i].toString()) {
123125
count++;
124126
break;
@@ -130,8 +132,11 @@ if (process.argv[2] !== 'child') {
130132
worker.pid,
131133
count);
132134

133-
assert.equal(count, messages.length,
134-
'A worker received an invalid multicast message');
135+
assert.strictEqual(
136+
count,
137+
messages.length,
138+
'A worker received an invalid multicast message'
139+
);
135140
});
136141

137142
clearTimeout(timer);
@@ -143,7 +148,7 @@ if (process.argv[2] !== 'child') {
143148
})(x);
144149
}
145150

146-
var sendSocket = dgram.createSocket({
151+
const sendSocket = dgram.createSocket({
147152
type: 'udp4',
148153
reuseAddr: true
149154
});
@@ -160,7 +165,7 @@ if (process.argv[2] !== 'child') {
160165
});
161166

162167
sendSocket.sendNext = function() {
163-
var buf = messages[i++];
168+
const buf = messages[i++];
164169

165170
if (!buf) {
166171
try { sendSocket.close(); } catch (e) {}
@@ -186,15 +191,15 @@ if (process.argv[2] !== 'child') {
186191

187192
function killChildren(children) {
188193
Object.keys(children).forEach(function(key) {
189-
var child = children[key];
194+
const child = children[key];
190195
child.kill();
191196
});
192197
}
193198
}
194199

195200
if (process.argv[2] === 'child') {
196-
var receivedMessages = [];
197-
var listenSocket = dgram.createSocket({
201+
const receivedMessages = [];
202+
const listenSocket = dgram.createSocket({
198203
type: 'udp4',
199204
reuseAddr: true
200205
});
@@ -212,7 +217,7 @@ if (process.argv[2] === 'child') {
212217

213218
process.send({message: buf.toString()});
214219

215-
if (receivedMessages.length == messages.length) {
220+
if (receivedMessages.length === messages.length) {
216221
process.nextTick(function() {
217222
listenSocket.close();
218223
});

0 commit comments

Comments
 (0)