Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 693a50e

Browse filesBrowse files
lundibundiMylesBorins
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 6fa033c commit 693a50e
Copy full SHA for 693a50e

File tree

Expand file treeCollapse file tree

1 file changed

+19
-21
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

1 file changed

+19
-21
lines changed
Open diff view settings
Collapse file

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

Copy file name to clipboardExpand all lines: test/sequential/test-gc-http-client-connaborted.js
+19-21Lines changed: 19 additions & 21 deletions
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 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.