Skip to content

Commit 91bad82

Browse files
lundibundijasnell
authored andcommitted
test: improve test-gc-http-client-connaborted
* refactor out usage of 'function' for scoping * wait till server is up to start firing requests PR-URL: #23193 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Joyee Cheung <joyeec9h3@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de> Reviewed-By: Luigi Pinca <luigipinca@gmail.com> Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
1 parent b61bbbb commit 91bad82

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

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

+19-21
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,9 @@
33
// just like test-gc-http-client.js,
44
// but aborting every connection that comes in.
55

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

9-
function serverHandler(req, res) {
10-
res.connection.destroy();
11-
}
12-
139
const http = require('http');
1410
const todo = 500;
1511
let done = 0;
@@ -18,33 +14,35 @@ let countGC = 0;
1814

1915
console.log(`We should do ${todo} requests`);
2016

17+
function serverHandler(req, res) {
18+
res.connection.destroy();
19+
}
20+
2121
const server = http.createServer(serverHandler);
22-
server.listen(0, getall);
22+
server.listen(0, common.mustCall(() => {
23+
for (let i = 0; i < 10; i++)
24+
getall();
25+
}));
2326

2427
function getall() {
2528
if (count >= todo)
2629
return;
2730

28-
(function() {
29-
function cb(res) {
30-
done += 1;
31-
}
31+
const req = http.get({
32+
hostname: 'localhost',
33+
pathname: '/',
34+
port: server.address().port
35+
}, cb).on('error', cb);
3236

33-
const req = http.get({
34-
hostname: 'localhost',
35-
pathname: '/',
36-
port: server.address().port
37-
}, cb).on('error', cb);
38-
39-
count++;
40-
onGC(req, { ongc });
41-
})();
37+
count++;
38+
onGC(req, { ongc });
4239

4340
setImmediate(getall);
4441
}
4542

46-
for (let i = 0; i < 10; i++)
47-
getall();
43+
function cb(res) {
44+
done += 1;
45+
}
4846

4947
function ongc() {
5048
countGC++;

0 commit comments

Comments
 (0)