Skip to content

Commit 71ecbd7

Browse files
committed
common.mustCall used
1 parent d32f212 commit 71ecbd7

File tree

1 file changed

+65
-50
lines changed

1 file changed

+65
-50
lines changed

test/parallel/test-net-socket-tos.js

Lines changed: 65 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -5,53 +5,68 @@ const net = require('net');
55

66
const isWindows = common.isWindows;
77

8-
const server = net.createServer(common.mustCall((socket) => {
9-
socket.end();
10-
}));
11-
12-
server.listen(0, common.mustCall(() => {
13-
const port = server.address().port;
14-
const client = net.connect(port);
15-
16-
client.on('connect', common.mustCall(() => {
17-
// TEST 1: setTOS validation
18-
// Should throw if value is not a number or out of range
19-
assert.throws(() => client.setTOS('invalid'), {
20-
code: 'ERR_INVALID_ARG_TYPE'
21-
});
22-
assert.throws(() => client.setTOS(NaN), {
23-
code: 'ERR_INVALID_ARG_TYPE'
24-
});
25-
assert.throws(() => client.setTOS(256), {
26-
code: 'ERR_OUT_OF_RANGE'
27-
});
28-
assert.throws(() => client.setTOS(-1), {
29-
code: 'ERR_OUT_OF_RANGE'
30-
});
31-
32-
// TEST 2: setting and getting TOS
33-
const tosValue = 0x10; // IPTOS_LOWDELAY (16)
34-
35-
if (isWindows) {
36-
// On Windows, your implementation returns UV_ENOSYS, which throws in JS
37-
assert.throws(() => client.setTOS(tosValue), {
38-
code: 'ENOSYS'
39-
});
40-
} else {
41-
// On POSIX (Linux/macOS), this should succeed
42-
client.setTOS(tosValue);
43-
44-
// Verify values
45-
// Note: Some OSs might mask the value (e.g. Linux sometimes masks ECN bits),
46-
// but usually 0x10 should return 0x10.
47-
const got = client.getTOS();
48-
assert.strictEqual(got, tosValue, `Expected TOS ${tosValue}, got ${got}`);
49-
}
50-
51-
client.end();
52-
}));
53-
54-
client.on('end', () => {
55-
server.close();
56-
});
57-
}));
8+
const server = net.createServer(
9+
common.mustCall((socket) => {
10+
socket.end();
11+
}),
12+
);
13+
14+
server.listen(
15+
0,
16+
common.mustCall(() => {
17+
const port = server.address().port;
18+
const client = net.connect(port);
19+
20+
client.on(
21+
'connect',
22+
common.mustCall(() => {
23+
// TEST 1: setTOS validation
24+
// Should throw if value is not a number or out of range
25+
assert.throws(() => client.setTOS('invalid'), {
26+
code: 'ERR_INVALID_ARG_TYPE',
27+
});
28+
assert.throws(() => client.setTOS(NaN), {
29+
code: 'ERR_INVALID_ARG_TYPE',
30+
});
31+
assert.throws(() => client.setTOS(256), {
32+
code: 'ERR_OUT_OF_RANGE',
33+
});
34+
assert.throws(() => client.setTOS(-1), {
35+
code: 'ERR_OUT_OF_RANGE',
36+
});
37+
38+
// TEST 2: setting and getting TOS
39+
const tosValue = 0x10; // IPTOS_LOWDELAY (16)
40+
41+
if (isWindows) {
42+
// On Windows, your implementation returns UV_ENOSYS, which throws in JS
43+
assert.throws(() => client.setTOS(tosValue), {
44+
code: 'ENOSYS',
45+
});
46+
} else {
47+
// On POSIX (Linux/macOS), this should succeed
48+
client.setTOS(tosValue);
49+
50+
// Verify values
51+
// Note: Some OSs might mask the value (e.g. Linux sometimes masks ECN bits),
52+
// but usually 0x10 should return 0x10.
53+
const got = client.getTOS();
54+
assert.strictEqual(
55+
got,
56+
tosValue,
57+
`Expected TOS ${tosValue}, got ${got}`,
58+
);
59+
}
60+
61+
client.end();
62+
}),
63+
);
64+
65+
client.on(
66+
'end',
67+
common.mustCall(() => {
68+
server.close();
69+
}),
70+
);
71+
}),
72+
);

0 commit comments

Comments
 (0)