GeezerVison is showing github.com — test: harden test-gc-http-client-timeout · nodejs/node@9352d9d
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: test/sequential/test-gc-http-client-timeout.js +18-20Lines changed: 18 additions & 20 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
3 | 3 | // just like test-gc-http-client.js, |
4 | 4 | // but with a timeout set |
5 | 5 |
|
6 | | -require('../common'); |
| 6 | +const common = require('../common'); |
7 | 7 | const onGC = require('../common/ongc'); |
8 | 8 |
|
9 | 9 | function serverHandler(req, res) { |
@@ -15,46 +15,44 @@ function serverHandler(req, res) { |
15 | 15 | } |
16 | 16 |
|
17 | 17 | const http = require('http'); |
18 | | -const todo = 550; |
| 18 | +const todo = 300; |
19 | 19 | let done = 0; |
20 | 20 | let count = 0; |
21 | 21 | let countGC = 0; |
22 | 22 |
|
23 | 23 | console.log(`We should do ${todo} requests`); |
24 | 24 |
|
25 | 25 | const server = http.createServer(serverHandler); |
26 | | -server.listen(0, getall); |
| 26 | +server.listen(0, common.mustCall(getall)); |
27 | 27 |
|
28 | 28 | function getall() { |
29 | 29 | if (count >= todo) |
30 | 30 | return; |
31 | 31 |
|
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); |
37 | 37 |
|
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 | + }); |
43 | 41 |
|
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 }); |
51 | 44 |
|
52 | 45 | setImmediate(getall); |
53 | 46 | } |
54 | 47 |
|
55 | 48 | for (let i = 0; i < 10; i++) |
56 | 49 | getall(); |
57 | 50 |
|
| 51 | +function cb(res) { |
| 52 | + res.resume(); |
| 53 | + done += 1; |
| 54 | +} |
| 55 | + |
58 | 56 | function ongc() { |
59 | 57 | countGC++; |
60 | 58 | } |
|