GeezerVison is showing github.com — test: Use countdown in test file · nodejs/node@bdb535c
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 clipboard +6-19Lines changed: 6 additions & 19 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
1 | 1 | 'use strict'; |
2 | 2 | require('../common'); |
3 | | -const assert = require('assert'); |
4 | 3 | const http = require('http'); |
5 | 4 | const net = require('net'); |
| 5 | +const Countdown = require('../common/countdown'); |
6 | 6 |
|
7 | 7 | const big = Buffer.alloc(16 * 1024, 'A'); |
8 | 8 |
|
9 | 9 | const COUNT = 1e4; |
10 | 10 |
|
11 | | -let received = 0; |
| 11 | +const countdown = new Countdown(COUNT, () => { |
| 12 | + server.close(); |
| 13 | + client.end(); |
| 14 | +}); |
12 | 15 |
|
13 | 16 | let client; |
14 | 17 | const server = http.createServer(function(req, res) { |
15 | 18 | res.end(big, function() { |
16 | | - if (++received === COUNT) { |
17 | | - server.close(); |
18 | | - client.end(); |
19 | | - } |
| 19 | + countdown.dec(); |
20 | 20 | }); |
21 | 21 | }).listen(0, function() { |
22 | 22 | const req = new Array(COUNT + 1).join('GET / HTTP/1.1\r\n\r\n'); |
23 | 23 | client = net.connect(this.address().port, function() { |
24 | 24 | client.write(req); |
25 | 25 | }); |
26 | | - |
27 | | - // Just let the test terminate instead of hanging |
28 | | - client.on('close', function() { |
29 | | - if (received !== COUNT) |
30 | | - server.close(); |
31 | | - }); |
32 | 26 | client.resume(); |
33 | 27 | }); |
34 | | - |
35 | | -process.on('exit', function() { |
36 | | - // The server should pause connection on pipeline flood, but it shoul still |
37 | | - // resume it and finish processing the requests, when its output queue will |
38 | | - // be empty again. |
39 | | - assert.strictEqual(received, COUNT); |
40 | | -}); |