Files
node/test/parallel/test-http-server-consumed-timeout.js
T
Trivikram Kamat 8e1ab55ac4 test: increase timeout in consumed-timeout test
Increase the base timeout in test-http-server-consumed-timeout from
common.platformTimeout(200) to common.platformTimeout(1000).

The test is intentionally timing-sensitive and can fail on slower or
more contended CI hosts when timers fire later than expected. Using a
larger timeout reduces false positives without changing the behavior
being tested.

Signed-off-by: Kamat, Trivikram <16024985+trivikr@users.noreply.github.com>
Assisted-by: openai:gpt-5.5
PR-URL: https://github.com/nodejs/node/pull/64204
Refs: https://ci.nodejs.org/job/node-stress-single-test/764/
Reviewed-By: Filip Skokan <panva.ip@gmail.com>
2026-07-08 00:59:28 +00:00

86 lines
2.5 KiB
JavaScript

'use strict';
const common = require('../common');
const assert = require('assert');
const http = require('http');
const durationBetweenIntervals = [];
let timeoutTooShort = false;
const TIMEOUT = common.platformTimeout(1000);
const INTERVAL = Math.floor(TIMEOUT / 8);
runTest(TIMEOUT);
function runTest(timeoutDuration) {
let intervalWasInvoked = false;
let newTimeoutDuration = 0;
const server = http.createServer(common.mustCallAtLeast((req, res) => {
server.close(common.mustSucceed(() => {
if (newTimeoutDuration) {
runTest(newTimeoutDuration);
}
}));
res.writeHead(200);
res.flushHeaders();
req.setTimeout(timeoutDuration, () => {
if (!intervalWasInvoked) {
// Interval wasn't invoked, probably because the machine is busy with
// other things. Try again with a longer timeout.
newTimeoutDuration = timeoutDuration * 2;
console.error('The interval was not invoked.');
console.error(`Trying w/ timeout of ${newTimeoutDuration}.`);
return;
}
if (timeoutTooShort) {
intervalWasInvoked = false;
timeoutTooShort = false;
newTimeoutDuration =
Math.max(...durationBetweenIntervals, timeoutDuration) * 2;
console.error(`Time between intervals: ${durationBetweenIntervals}`);
console.error(`Trying w/ timeout of ${newTimeoutDuration}`);
return;
}
assert.fail('Request timeout should not fire');
});
req.resume();
req.once('end', () => {
res.end();
});
}));
server.listen(0, common.mustCall(() => {
const req = http.request({
port: server.address().port,
method: 'POST',
agent: false,
}, () => {
let lastIntervalTimestamp = Date.now();
const interval = setInterval(() => {
const lastDuration = Date.now() - lastIntervalTimestamp;
durationBetweenIntervals.push(lastDuration);
lastIntervalTimestamp = Date.now();
if (lastDuration > timeoutDuration / 2) {
// The interval is supposed to be about 1/8 of the timeout duration.
// If it's running so infrequently that it's greater than 1/2 the
// timeout duration, then run the test again with a longer timeout.
timeoutTooShort = true;
}
intervalWasInvoked = true;
req.write('a');
}, INTERVAL);
setTimeout(() => {
clearInterval(interval);
req.end();
}, timeoutDuration);
});
req.write('.');
}));
}