forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
/
test-net-connect-nodelay.js
49 lines (37 loc) · 1.13 KB
/
test-net-connect-nodelay.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
'use strict';
const common = require('../common');
const assert = require('assert');
const net = require('net');
const truthyValues = [true, 1, 'true', {}, []];
const falseyValues = [false, 0, ''];
const genSetNoDelay = (desiredArg) => (enable) => {
assert.strictEqual(enable, desiredArg);
};
for (const value of truthyValues) {
const server = net.createServer();
server.listen(0, common.mustCall(function() {
const port = server.address().port;
const client = net.connect(
{ port, noDelay: value },
common.mustCall(() => client.end())
);
client._handle.setNoDelay = common.mustCall(genSetNoDelay(true));
client.on('end', common.mustCall(function() {
server.close();
}));
}));
}
for (const value of falseyValues) {
const server = net.createServer();
server.listen(0, common.mustCall(function() {
const port = server.address().port;
const client = net.connect(
{ port, noDelay: value },
common.mustCall(() => client.end())
);
client._handle.setNoDelay = common.mustNotCall();
client.on('end', common.mustCall(function() {
server.close();
}));
}));
}