Skip to content

Commit dbe45b7

Browse files
authored
test: ensure assertions are reachable in test/internet
PR-URL: #60513 Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Chemi Atlow <chemi@atlow.co.il>
1 parent 85ee01c commit dbe45b7

16 files changed

+245
-267
lines changed

test/eslint.config_partial.mjs

Lines changed: 1 addition & 0 deletions
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',

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
}

test/internet/test-dns-any.js

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ function checkWrap(req) {
1919
assert.ok(typeof req === 'object');
2020
}
2121

22+
/* eslint-disable node-core/must-call-assert */
2223
const checkers = {
2324
checkA(r) {
2425
assert.ok(isIPv4(r.address));
@@ -80,13 +81,14 @@ const checkers = {
8081
assert.strictEqual(r.type, 'SRV');
8182
},
8283
};
84+
/* eslint-enable node-core/must-call-assert */
8385

84-
function TEST(f) {
86+
function test(f) {
8587
function next() {
8688
const f = queue.shift();
8789
if (f) {
8890
running = true;
89-
f(done);
91+
f(done).then(common.mustCall());
9092
}
9193
}
9294

@@ -115,7 +117,7 @@ function processResult(res) {
115117
return types;
116118
}
117119

118-
TEST(async function test_sip2sip_for_naptr(done) {
120+
test(async function test_sip2sip_for_naptr(done) {
119121
function validateResult(res) {
120122
const types = processResult(res);
121123
assert.ok(types.A && types.NS && types.NAPTR && types.SOA,
@@ -135,7 +137,7 @@ TEST(async function test_sip2sip_for_naptr(done) {
135137
checkWrap(req);
136138
});
137139

138-
TEST(async function test_google_for_cname_and_srv(done) {
140+
test(async function test_google_for_cname_and_srv(done) {
139141
function validateResult(res) {
140142
const types = processResult(res);
141143
assert.ok(types.SRV);
@@ -154,7 +156,7 @@ TEST(async function test_google_for_cname_and_srv(done) {
154156
checkWrap(req);
155157
});
156158

157-
TEST(async function test_ptr(done) {
159+
test(async function test_ptr(done) {
158160
function validateResult(res) {
159161
const types = processResult(res);
160162
assert.ok(types.PTR);

test/internet/test-dns-cares-domains.js

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ const assert = require('assert');
55
const dns = require('dns');
66
const domain = require('domain');
77

8-
const methods = [
8+
[
99
'resolve4',
1010
'resolve6',
1111
'resolveCname',
@@ -17,13 +17,11 @@ const methods = [
1717
'resolvePtr',
1818
'resolveNaptr',
1919
'resolveSoa',
20-
];
21-
22-
methods.forEach(function(method) {
20+
].forEach(function(method) {
2321
const d = domain.create();
24-
d.run(function() {
22+
d.run(common.mustCall(() => {
2523
dns[method](addresses.INET_HOST, common.mustCall(() => {
2624
assert.strictEqual(process.domain, d, `${method} retains domain`);
2725
}));
28-
});
26+
}));
2927
});

0 commit comments

Comments
 (0)