Skip to content

Commit e5e9c64

Browse files
rpamelyBridgeAR
authored andcommitted
test: dgram socket prints deprecation warnings
Adds tests assert the deprecated properties and methods in the dgram socket warn. It runs each test in a separate child process since each deprecation will only warn once. PR-URL: #24177 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 44ebdbb commit e5e9c64

File tree

1 file changed

+84
-0
lines changed

1 file changed

+84
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,84 @@
1+
'use strict';
2+
3+
const assert = require('assert');
4+
const common = require('../common');
5+
const dgram = require('dgram');
6+
const fork = require('child_process').fork;
7+
8+
const sock = dgram.createSocket('udp4');
9+
10+
const testNumber = parseInt(process.argv[2], 10);
11+
12+
const propertiesToTest = [
13+
'_handle',
14+
'_receiving',
15+
'_bindState',
16+
'_queue',
17+
'_reuseAddr'
18+
];
19+
20+
const methodsToTest = [
21+
'_healthCheck',
22+
'_stopReceiving'
23+
];
24+
25+
const propertyCases = propertiesToTest.map((propName) => {
26+
return [
27+
() => {
28+
// Test property getter
29+
common.expectWarning(
30+
'DeprecationWarning',
31+
`Socket.prototype.${propName} is deprecated`,
32+
'DEP0112'
33+
);
34+
sock[propName];
35+
},
36+
() => {
37+
// Test property setter
38+
common.expectWarning(
39+
'DeprecationWarning',
40+
`Socket.prototype.${propName} is deprecated`,
41+
'DEP0112'
42+
);
43+
sock[propName] = null;
44+
}
45+
];
46+
});
47+
48+
const methodCases = methodsToTest.map((propName) => {
49+
return () => {
50+
common.expectWarning(
51+
'DeprecationWarning',
52+
`Socket.prototype.${propName}() is deprecated`,
53+
'DEP0112'
54+
);
55+
sock[propName]();
56+
};
57+
});
58+
59+
const cases = [].concat(
60+
...propertyCases,
61+
...methodCases
62+
);
63+
64+
// If we weren't passed a test ID then we need to spawn all of the cases.
65+
// We run the cases in child processes since deprecations print once.
66+
if (Number.isNaN(testNumber)) {
67+
const children = cases.map((_case, i) =>
68+
fork(process.argv[1], [ String(i) ]));
69+
70+
children.forEach((child) => {
71+
child.on('close', (code) => {
72+
// Pass on child exit code
73+
if (code > 0) {
74+
process.exit(code);
75+
}
76+
});
77+
});
78+
79+
return;
80+
}
81+
82+
// We were passed a test ID - run the test case
83+
assert.ok(cases[testNumber]);
84+
cases[testNumber]();

0 commit comments

Comments
 (0)