Skip to content

Commit 149c209

Browse files
BridgeARtargos
authored andcommitted
test: harden test-gc-http-client
This reduces the total number of requests from 500 to 300 and triggers more requests in parallel. It also moves some function creation out and waits with the first request until the server is listening. PR-URL: #22373 Fixes: #22336 Reviewed-By: Joyee Cheung <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 2b1cb3b commit 149c209

File tree

1 file changed

+18
-22
lines changed

1 file changed

+18
-22
lines changed

test/parallel/test-gc-http-client.js

+18-22
Original file line numberDiff line numberDiff line change
@@ -10,44 +10,40 @@ function serverHandler(req, res) {
1010
}
1111

1212
const http = require('http');
13-
const todo = 500;
13+
const todo = 300;
1414
let done = 0;
1515
let count = 0;
1616
let countGC = 0;
1717

1818
console.log(`We should do ${todo} requests`);
1919

2020
const server = http.createServer(serverHandler);
21-
server.listen(0, getall);
22-
21+
server.listen(0, common.mustCall(() => {
22+
for (let i = 0; i < 15; i++)
23+
getall();
24+
}));
2325

2426
function getall() {
25-
if (count >= todo)
27+
if (count === todo)
2628
return;
2729

28-
(function() {
29-
function cb(res) {
30-
res.resume();
31-
console.error('in cb');
32-
done += 1;
33-
res.on('end', global.gc);
34-
}
35-
36-
const req = http.get({
37-
hostname: 'localhost',
38-
pathname: '/',
39-
port: server.address().port
40-
}, cb);
30+
const req = http.get({
31+
hostname: 'localhost',
32+
pathname: '/',
33+
port: server.address().port
34+
}, cb);
4135

42-
count++;
43-
common.onGC(req, { ongc });
44-
})();
36+
count++;
37+
common.onGC(req, { ongc });
4538

4639
setImmediate(getall);
4740
}
4841

49-
for (let i = 0; i < 10; i++)
50-
getall();
42+
function cb(res) {
43+
res.resume();
44+
done += 1;
45+
res.on('end', global.gc);
46+
}
5147

5248
function ongc() {
5349
countGC++;

0 commit comments

Comments
 (0)