Skip to content

Commit bc07c8f

Browse files
committed
fixup! test: ensure assertions are reachable in test/internet
1 parent f450628 commit bc07c8f

11 files changed

+205
-228
lines changed

test/eslint.config_partial.mjs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ export default [
167167
'embedding',
168168
'fixtures',
169169
'fuzzers',
170+
'internet',
170171
'js-native-api',
171172
'known_issues',
172173
'message',
@@ -190,7 +191,6 @@ export default [
190191
'wasm-allocation',
191192
'wpt',
192193
].join(',')}}/**/*.{js,mjs,cjs}`,
193-
'test/internet/test-dns-*.{js,mjs,cjs}',
194194
],
195195
rules: {
196196
'node-core/must-call-assert': 'error',

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

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ if (process.argv[2] !== 'child') {
8484
worker.messagesReceived = [];
8585

8686
// Handle the death of workers
87-
worker.on('exit', (code, signal) => {
87+
worker.on('exit', common.mustCall((code, signal) => {
8888
// Don't consider this the true death if the worker
8989
// has finished successfully
9090
// or if the exit code is 0
@@ -108,9 +108,9 @@ if (process.argv[2] !== 'child') {
108108

109109
process.exit(1);
110110
}
111-
});
111+
}));
112112

113-
worker.on('message', (msg) => {
113+
worker.on('message', common.mustCallAtLeast((msg) => {
114114
if (msg.listening) {
115115
listening += 1;
116116

@@ -134,7 +134,7 @@ if (process.argv[2] !== 'child') {
134134
'required number of ' +
135135
'messages. Will now compare.');
136136

137-
Object.keys(workers).forEach((pid) => {
137+
for (const pid of Object.keys(workers)) {
138138
const worker = workers[pid];
139139

140140
let count = 0;
@@ -153,14 +153,14 @@ if (process.argv[2] !== 'child') {
153153
count);
154154

155155
assert.strictEqual(count, messages.length);
156-
});
156+
}
157157

158158
clearTimeout(timer);
159159
console.error('[PARENT] Success');
160160
killSubprocesses(workers);
161161
}
162162
}
163-
});
163+
}));
164164
})(x);
165165
}
166166

@@ -196,14 +196,13 @@ if (process.argv[2] !== 'child') {
196196
buf.length,
197197
common.PORT,
198198
LOCAL_BROADCAST_HOST,
199-
(err) => {
200-
assert.ifError(err);
199+
common.mustSucceed(() => {
201200
console.error('[PARENT] sent %s to %s:%s',
202201
util.inspect(buf.toString()),
203202
LOCAL_BROADCAST_HOST, common.PORT);
204203

205204
process.nextTick(sendSocket.sendNext);
206-
},
205+
}),
207206
);
208207
};
209208

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

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ function launchChildProcess() {
6969
}
7070
});
7171

72-
worker.on('message', function(msg) {
72+
worker.on('message', common.mustCallAtLeast((msg) => {
7373
if (msg.listening) {
7474
listening += 1;
7575

@@ -94,7 +94,7 @@ function launchChildProcess() {
9494
console.error('[PARENT] All workers have received the ' +
9595
'required number of messages. Will now compare.');
9696

97-
Object.keys(workers).forEach(function(pid) {
97+
for (const pid of Object.keys(workers)) {
9898
const worker = workers[pid];
9999

100100
let count = 0;
@@ -112,14 +112,14 @@ function launchChildProcess() {
112112
worker.pid, count);
113113

114114
assert.strictEqual(count, messages.length);
115-
});
115+
}
116116

117117
clearTimeout(timer);
118118
console.error('[PARENT] Success');
119119
killSubprocesses(workers);
120120
}
121121
}
122-
});
122+
}));
123123
}
124124

125125
function killSubprocesses(subprocesses) {
@@ -182,13 +182,12 @@ if (process.argv[2] !== 'child') {
182182
buf.length,
183183
common.PORT,
184184
LOCAL_BROADCAST_HOST,
185-
function(err) {
186-
assert.ifError(err);
185+
common.mustSucceed(() => {
187186
console.error('[PARENT] sent "%s" to %s:%s',
188187
buf.toString(),
189188
LOCAL_BROADCAST_HOST, common.PORT);
190189
process.nextTick(sendSocket.sendNext);
191-
},
190+
}),
192191
);
193192
};
194193
}

test/internet/test-dgram-multicast-set-interface-lo.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ if (process.argv[2] !== 'child') {
144144
}
145145
});
146146

147-
worker.on('message', (msg) => {
147+
worker.on('message', common.mustCallAtLeast((msg) => {
148148
if (msg.listening) {
149149
listening += 1;
150150

@@ -168,7 +168,7 @@ if (process.argv[2] !== 'child') {
168168
'required number of ' +
169169
'messages. Will now compare.');
170170

171-
Object.keys(workers).forEach((pid) => {
171+
for (const pid of Object.keys(workers)) {
172172
const worker = workers[pid];
173173

174174
let count = 0;
@@ -189,14 +189,14 @@ if (process.argv[2] !== 'child') {
189189
assert.strictEqual(count, worker.messagesNeeded.length,
190190
'A worker received ' +
191191
'an invalid multicast message');
192-
});
192+
}
193193

194194
clearTimeout(timer);
195195
console.error('[PARENT] Success');
196196
killSubprocesses(workers);
197197
}
198198
}
199-
});
199+
}));
200200
}
201201

202202
const sendSocket = dgram.createSocket({
@@ -234,14 +234,13 @@ if (process.argv[2] !== 'child') {
234234
buf.length,
235235
PORTS[msg.mcast],
236236
msg.mcast,
237-
(err) => {
238-
assert.ifError(err);
237+
common.mustSucceed(() => {
239238
console.error('[PARENT] sent %s to %s:%s',
240239
util.inspect(buf.toString()),
241240
msg.mcast, PORTS[msg.mcast]);
242241

243242
process.nextTick(sendSocket.sendNext);
244-
},
243+
}),
245244
);
246245
};
247246
}

test/internet/test-dgram-multicast-ssm-multi-process.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function launchChildProcess() {
6363
}
6464
});
6565

66-
worker.on('message', function(msg) {
66+
worker.on('message', common.mustCallAtLeast((msg) => {
6767
if (msg.listening) {
6868
listening += 1;
6969

@@ -88,7 +88,7 @@ function launchChildProcess() {
8888
console.error('[PARENT] All workers have received the ' +
8989
'required number of messages. Will now compare.');
9090

91-
Object.keys(workers).forEach(function(pid) {
91+
for (const pid of Object.keys(workers)) {
9292
const worker = workers[pid];
9393

9494
let count = 0;
@@ -106,14 +106,14 @@ function launchChildProcess() {
106106
worker.pid, count);
107107

108108
assert.strictEqual(count, messages.length);
109-
});
109+
}
110110

111111
clearTimeout(timer);
112112
console.error('[PARENT] Success');
113113
killChildren(workers);
114114
}
115115
}
116-
});
116+
}));
117117
}
118118

119119
function killChildren(children) {
@@ -176,13 +176,12 @@ if (process.argv[2] !== 'child') {
176176
buf.length,
177177
common.PORT,
178178
GROUP_ADDRESS,
179-
function(err) {
180-
assert.ifError(err);
179+
common.mustSucceed((err) => {
181180
console.error('[PARENT] sent "%s" to %s:%s',
182181
buf.toString(),
183182
GROUP_ADDRESS, common.PORT);
184183
process.nextTick(sendSocket.sendNext);
185-
},
184+
}),
186185
);
187186
};
188187
}

test/internet/test-dgram-multicast-ssmv6-multi-process.js

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ function launchChildProcess() {
6363
}
6464
});
6565

66-
worker.on('message', function(msg) {
66+
worker.on('message', common.mustCallAtLeast((msg) => {
6767
if (msg.listening) {
6868
listening += 1;
6969

@@ -88,7 +88,7 @@ function launchChildProcess() {
8888
console.error('[PARENT] All workers have received the ' +
8989
'required number of messages. Will now compare.');
9090

91-
Object.keys(workers).forEach(function(pid) {
91+
for (const pid of Object.keys(workers)) {
9292
const worker = workers[pid];
9393

9494
let count = 0;
@@ -106,14 +106,14 @@ function launchChildProcess() {
106106
worker.pid, count);
107107

108108
assert.strictEqual(count, messages.length);
109-
});
109+
}
110110

111111
clearTimeout(timer);
112112
console.error('[PARENT] Success');
113113
killChildren(workers);
114114
}
115115
}
116-
});
116+
}));
117117
}
118118

119119
function killChildren(children) {
@@ -176,13 +176,12 @@ if (process.argv[2] !== 'child') {
176176
buf.length,
177177
common.PORT,
178178
GROUP_ADDRESS,
179-
function(err) {
180-
assert.ifError(err);
179+
common.mustSucceed(() => {
181180
console.error('[PARENT] sent "%s" to %s:%s',
182181
buf.toString(),
183182
GROUP_ADDRESS, common.PORT);
184183
process.nextTick(sendSocket.sendNext);
185-
},
184+
}),
186185
);
187186
};
188187
}

0 commit comments

Comments
 (0)