Skip to content

Commit 830049f

Browse files
Trottjasnell
authored andcommitted
test: refactor test-net-server-bind
* Use common.mustNotCall() and common.mustCall() as appropriate * Use block scoping * Move assertions out of `exit` handler and into callbacks * Order assert.strictEqual() args per docs * Remove console.log() calls * Move test from `parallel` to `sequential` so `common.PORT` can be used without conflicting with OS-provided ports in other `parallel` tests PR-URL: #13273 Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Luigi Pinca <[email protected]>
1 parent c2d7b41 commit 830049f

File tree

2 files changed

+64
-86
lines changed

2 files changed

+64
-86
lines changed

test/parallel/test-net-server-bind.js

-86
This file was deleted.
+64
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,64 @@
1+
'use strict';
2+
const common = require('../common');
3+
const assert = require('assert');
4+
const net = require('net');
5+
6+
7+
// With only a callback, server should get a port assigned by the OS
8+
{
9+
const server = net.createServer(common.mustNotCall());
10+
11+
server.listen(common.mustCall(function() {
12+
assert.ok(server.address().port > 100);
13+
server.close();
14+
}));
15+
}
16+
17+
// No callback to listen(), assume we can bind in 100 ms
18+
{
19+
const server = net.createServer(common.mustNotCall());
20+
21+
server.listen(common.PORT);
22+
23+
setTimeout(function() {
24+
const address = server.address();
25+
assert.strictEqual(address.port, common.PORT);
26+
27+
if (address.family === 'IPv6')
28+
assert.strictEqual(server._connectionKey, `6::::${address.port}`);
29+
else
30+
assert.strictEqual(server._connectionKey, `4:0.0.0.0:${address.port}`);
31+
32+
server.close();
33+
}, 100);
34+
}
35+
36+
// Callback to listen()
37+
{
38+
const server = net.createServer(common.mustNotCall());
39+
40+
server.listen(common.PORT + 1, common.mustCall(function() {
41+
assert.strictEqual(server.address().port, common.PORT + 1);
42+
server.close();
43+
}));
44+
}
45+
46+
// Backlog argument
47+
{
48+
const server = net.createServer(common.mustNotCall());
49+
50+
server.listen(common.PORT + 2, '0.0.0.0', 127, common.mustCall(function() {
51+
assert.strictEqual(server.address().port, common.PORT + 2);
52+
server.close();
53+
}));
54+
}
55+
56+
// Backlog argument without host argument
57+
{
58+
const server = net.createServer(common.mustNotCall());
59+
60+
server.listen(common.PORT + 3, 127, common.mustCall(function() {
61+
assert.strictEqual(server.address().port, common.PORT + 3);
62+
server.close();
63+
}));
64+
}

0 commit comments

Comments
 (0)