forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest-http-agent-keep-alive-timeout-buffer.js
More file actions
44 lines (35 loc) · 1.42 KB
/
test-http-agent-keep-alive-timeout-buffer.js
File metadata and controls
44 lines (35 loc) · 1.42 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
'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
// Ensure agentKeepAliveTimeoutBuffer option sets the correct value or falls back to default.
{
const agent1 = new http.Agent({ agentKeepAliveTimeoutBuffer: 1500, keepAlive: true });
assert.strictEqual(agent1.agentKeepAliveTimeoutBuffer, 1500);
const agent2 = new http.Agent({ agentKeepAliveTimeoutBuffer: -100, keepAlive: true });
assert.strictEqual(agent2.agentKeepAliveTimeoutBuffer, 1000);
const agent3 = new http.Agent({ agentKeepAliveTimeoutBuffer: Infinity, keepAlive: true });
assert.strictEqual(agent3.agentKeepAliveTimeoutBuffer, 1000);
const agent4 = new http.Agent({ keepAlive: true });
assert.strictEqual(agent4.agentKeepAliveTimeoutBuffer, 1000);
}
// Integration test with server sending Keep-Alive timeout header.
{
const SERVER_TIMEOUT = 3;
const BUFFER = 1500;
const server = http.createServer((req, res) => {
res.setHeader('Keep-Alive', `timeout=${SERVER_TIMEOUT}`);
res.end('ok');
});
server.listen(0, common.mustCall(() => {
const agent = new http.Agent({ agentKeepAliveTimeoutBuffer: BUFFER, keepAlive: true });
assert.strictEqual(agent.agentKeepAliveTimeoutBuffer, BUFFER);
http.get({ port: server.address().port, agent }, (res) => {
res.resume();
res.on('end', () => {
agent.destroy();
server.close();
});
});
}));
}