mirror of
https://github.com/nodejs/node.git
synced 2025-08-16 06:08:50 +02:00
test: improve test-gc-http-client-timeout
test-gc-http-client-timeout is resource-intensive. It times out a lot on CI. Move to sequential. Approved for fast-tracking by: Anna Henningsen <anna@addaleax.net> Daniel Bevenius <daniel.bevenius@gmail.com> PR-URL: https://github.com/nodejs/node/pull/23088 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Trivikram Kamat <trivikr.dev@gmail.com>
This commit is contained in:
parent
7d03ff188a
commit
c6c0f3b32c
1 changed files with 0 additions and 0 deletions
69
test/sequential/test-gc-http-client-timeout.js
Normal file
69
test/sequential/test-gc-http-client-timeout.js
Normal file
|
@ -0,0 +1,69 @@
|
|||
'use strict';
|
||||
// Flags: --expose-gc
|
||||
// just like test-gc-http-client.js,
|
||||
// but with a timeout set
|
||||
|
||||
require('../common');
|
||||
const onGC = require('../common/ongc');
|
||||
|
||||
function serverHandler(req, res) {
|
||||
setTimeout(function() {
|
||||
req.resume();
|
||||
res.writeHead(200);
|
||||
res.end('hello\n');
|
||||
}, 100);
|
||||
}
|
||||
|
||||
const http = require('http');
|
||||
const todo = 550;
|
||||
let done = 0;
|
||||
let count = 0;
|
||||
let countGC = 0;
|
||||
|
||||
console.log(`We should do ${todo} requests`);
|
||||
|
||||
const server = http.createServer(serverHandler);
|
||||
server.listen(0, getall);
|
||||
|
||||
function getall() {
|
||||
if (count >= todo)
|
||||
return;
|
||||
|
||||
(function() {
|
||||
function cb(res) {
|
||||
res.resume();
|
||||
done += 1;
|
||||
}
|
||||
|
||||
const req = http.get({
|
||||
hostname: 'localhost',
|
||||
pathname: '/',
|
||||
port: server.address().port
|
||||
}, cb);
|
||||
|
||||
req.setTimeout(10, function() {
|
||||
console.log('timeout (expected)');
|
||||
});
|
||||
|
||||
count++;
|
||||
onGC(req, { ongc });
|
||||
})();
|
||||
|
||||
setImmediate(getall);
|
||||
}
|
||||
|
||||
for (let i = 0; i < 10; i++)
|
||||
getall();
|
||||
|
||||
function ongc() {
|
||||
countGC++;
|
||||
}
|
||||
|
||||
setInterval(status, 100).unref();
|
||||
|
||||
function status() {
|
||||
global.gc();
|
||||
console.log('Done: %d/%d', done, todo);
|
||||
console.log('Collected: %d/%d', countGC, count);
|
||||
if (countGC === todo) server.close();
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue