forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-tls-connect-keepalive-nodelay.js
More file actions
65 lines (56 loc) · 1.71 KB
/
Copy pathtest-tls-connect-keepalive-nodelay.js
File metadata and controls
65 lines (56 loc) · 1.71 KB
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
65
// Flags: --expose-internals
'use strict';
const common = require('../common');
// This test verifies that tls.connect() forwards keepAlive,
// keepAliveInitialDelay, and noDelay options to the underlying socket.
if (!common.hasCrypto)
common.skip('missing crypto');
const assert = require('assert');
const tls = require('tls');
const fixtures = require('../common/fixtures');
const {
kSetNoDelay,
kSetKeepAlive,
kSetKeepAliveInitialDelay,
} = require('internal/net');
const key = fixtures.readKey('agent1-key.pem');
const cert = fixtures.readKey('agent1-cert.pem');
// Test: keepAlive, keepAliveInitialDelay, and noDelay
{
const server = tls.createServer({ key, cert }, (socket) => {
socket.end();
});
server.listen(0, common.mustCall(() => {
const socket = tls.connect({
port: server.address().port,
rejectUnauthorized: false,
keepAlive: true,
keepAliveInitialDelay: 1000,
noDelay: true,
}, common.mustCall(() => {
assert.strictEqual(socket[kSetKeepAlive], true);
assert.strictEqual(socket[kSetKeepAliveInitialDelay], 1);
assert.strictEqual(socket[kSetNoDelay], true);
socket.destroy();
server.close();
}));
}));
}
// Test: defaults (options not set)
{
const server = tls.createServer({ key, cert }, (socket) => {
socket.end();
});
server.listen(0, common.mustCall(() => {
const socket = tls.connect({
port: server.address().port,
rejectUnauthorized: false,
}, common.mustCall(() => {
assert.strictEqual(socket[kSetKeepAlive], false);
assert.strictEqual(socket[kSetKeepAliveInitialDelay], 0);
assert.strictEqual(socket[kSetNoDelay], false);
socket.destroy();
server.close();
}));
}));
}