Skip to content

Commit 939a27e

Browse files
lundibundijasnell
authored andcommitted
test: improve test-gc-http-client-onerror
* refactor out usage of 'function' for scoping * inline runTest function PR-URL: #23196 Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
1 parent 91bad82 commit 939a27e

File tree

1 file changed

+19
-22
lines changed

1 file changed

+19
-22
lines changed

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

+19-22
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// just like test-gc-http-client.js,
44
// but with an on('error') handler that does nothing.
55

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

99
function serverHandler(req, res) {
@@ -21,37 +21,34 @@ let countGC = 0;
2121
console.log(`We should do ${todo} requests`);
2222

2323
const server = http.createServer(serverHandler);
24-
server.listen(0, runTest);
24+
server.listen(0, common.mustCall(() => {
25+
for (let i = 0; i < 10; i++)
26+
getall();
27+
}));
2528

2629
function getall() {
2730
if (count >= todo)
2831
return;
2932

30-
(function() {
31-
function cb(res) {
32-
res.resume();
33-
done += 1;
34-
}
35-
function onerror(er) {
36-
throw er;
37-
}
33+
const req = http.get({
34+
hostname: 'localhost',
35+
pathname: '/',
36+
port: server.address().port
37+
}, cb).on('error', onerror);
3838

39-
const req = http.get({
40-
hostname: 'localhost',
41-
pathname: '/',
42-
port: server.address().port
43-
}, cb).on('error', onerror);
44-
45-
count++;
46-
onGC(req, { ongc });
47-
})();
39+
count++;
40+
onGC(req, { ongc });
4841

4942
setImmediate(getall);
5043
}
5144

52-
function runTest() {
53-
for (let i = 0; i < 10; i++)
54-
getall();
45+
function cb(res) {
46+
res.resume();
47+
done += 1;
48+
}
49+
50+
function onerror(err) {
51+
throw err;
5552
}
5653

5754
function ongc() {

0 commit comments

Comments
 (0)