mirror of
https://github.com/nodejs/node.git
synced 2025-08-15 13:48:44 +02:00

Some checks failed
Coverage Windows / coverage-windows (push) Waiting to run
Coverage Linux (without intl) / coverage-linux-without-intl (push) Failing after 1m45s
Coverage Linux / coverage-linux (push) Failing after 1m1s
Test and upload documentation to artifacts / build-docs (push) Failing after 6m37s
Linters / lint-addon-docs (push) Successful in 2m28s
Linters / lint-cpp (push) Successful in 4m20s
Linters / format-cpp (push) Has been skipped
Linters / lint-py (push) Successful in 2m39s
Linters / lint-yaml (push) Successful in 2m32s
Linters / lint-sh (push) Failing after 1m41s
Linters / lint-codeowners (push) Failing after 56s
Linters / lint-pr-url (push) Has been skipped
Linters / lint-readme (push) Successful in 1m24s
Notify on Push / Notify on Force Push on `main` (push) Has been skipped
Linters / lint-js-and-md (push) Successful in 14m58s
Notify on Push / Notify on Push on `main` that lacks metadata (push) Has been skipped
Scorecard supply-chain security / Scorecard analysis (push) Failing after 52s
PR-URL: https://github.com/nodejs/node/pull/59315 Reviewed-By: Jason Zhang <xzha4350@gmail.com>
44 lines
1.4 KiB
JavaScript
44 lines
1.4 KiB
JavaScript
'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();
|
|
});
|
|
});
|
|
}));
|
|
}
|