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