Skip to content

Commit 9352d9d

Browse files
lundibunditargos
authored andcommitted
test: harden test-gc-http-client-timeout
* decrease number of requests 500 -> 300 * extract 'cb' to a file-local function This should make test more reliable and less resource intensive. PR-URL: #23184 Refs: #23066 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]> Reviewed-By: Ruben Bridgewater <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 49b0ec4 commit 9352d9d

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

test/sequential/test-gc-http-client-timeout.js

+18-20
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// just like test-gc-http-client.js,
44
// but with a timeout set
55

6-
require('../common');
6+
const common = require('../common');
77
const onGC = require('../common/ongc');
88

99
function serverHandler(req, res) {
@@ -15,46 +15,44 @@ function serverHandler(req, res) {
1515
}
1616

1717
const http = require('http');
18-
const todo = 550;
18+
const todo = 300;
1919
let done = 0;
2020
let count = 0;
2121
let countGC = 0;
2222

2323
console.log(`We should do ${todo} requests`);
2424

2525
const server = http.createServer(serverHandler);
26-
server.listen(0, getall);
26+
server.listen(0, common.mustCall(getall));
2727

2828
function getall() {
2929
if (count >= todo)
3030
return;
3131

32-
(function() {
33-
function cb(res) {
34-
res.resume();
35-
done += 1;
36-
}
32+
const req = http.get({
33+
hostname: 'localhost',
34+
pathname: '/',
35+
port: server.address().port
36+
}, cb);
3737

38-
const req = http.get({
39-
hostname: 'localhost',
40-
pathname: '/',
41-
port: server.address().port
42-
}, cb);
38+
req.setTimeout(10, function() {
39+
console.log('timeout (expected)');
40+
});
4341

44-
req.setTimeout(10, function() {
45-
console.log('timeout (expected)');
46-
});
47-
48-
count++;
49-
onGC(req, { ongc });
50-
})();
42+
count++;
43+
onGC(req, { ongc });
5144

5245
setImmediate(getall);
5346
}
5447

5548
for (let i = 0; i < 10; i++)
5649
getall();
5750

51+
function cb(res) {
52+
res.resume();
53+
done += 1;
54+
}
55+
5856
function ongc() {
5957
countGC++;
6058
}

0 commit comments

Comments
 (0)