|
2 | 2 | require('../common'); |
3 | 3 | const assert = require('assert'); |
4 | 4 | const http = require('http'); |
5 | | -const Countdown = require('../common/countdown'); |
6 | 5 |
|
7 | | -const test_res_body = 'other stuff!\n'; |
8 | | -const countdown = new Countdown(3, () => server.close()); |
| 6 | +const testResBody = 'other stuff!\n'; |
| 7 | +const kMessageCount = 2; |
9 | 8 |
|
10 | 9 | const server = http.createServer((req, res) => { |
11 | | - console.error('Server sending informational message #1...'); |
12 | | - res.writeProcessing(); |
13 | | - console.error('Server sending informational message #2...'); |
14 | | - res.writeProcessing(); |
| 10 | + for (let i = 0; i < kMessageCount; i++) { |
| 11 | + console.error(`Server sending informational message #${i}...`); |
| 12 | + res.writeProcessing(); |
| 13 | + } |
15 | 14 | console.error('Server sending full response...'); |
16 | 15 | res.writeHead(200, { |
17 | 16 | 'Content-Type': 'text/plain', |
18 | 17 | 'ABCD': '1' |
19 | 18 | }); |
20 | | - res.end(test_res_body); |
| 19 | + res.end(testResBody); |
21 | 20 | }); |
22 | 21 |
|
23 | 22 | server.listen(0, function() { |
@@ -29,24 +28,22 @@ server.listen(0, function() { |
29 | 28 | console.error('Client sending request...'); |
30 | 29 |
|
31 | 30 | let body = ''; |
| 31 | + let infoCount = 0; |
32 | 32 |
|
33 | | - req.on('information', function(res) { |
34 | | - console.error('Client got 102 Processing...'); |
35 | | - countdown.dec(); |
36 | | - }); |
| 33 | + req.on('information', () => { infoCount++; }); |
37 | 34 |
|
38 | 35 | req.on('response', function(res) { |
39 | 36 | // Check that all 102 Processing received before full response received. |
40 | | - assert.strictEqual(countdown.remaining, 1); |
| 37 | + assert.strictEqual(infoCount, kMessageCount); |
41 | 38 | assert.strictEqual(res.statusCode, 200, |
42 | 39 | `Final status code was ${res.statusCode}, not 200.`); |
43 | 40 | res.setEncoding('utf8'); |
44 | 41 | res.on('data', function(chunk) { body += chunk; }); |
45 | 42 | res.on('end', function() { |
46 | 43 | console.error('Got full response.'); |
47 | | - assert.strictEqual(body, test_res_body); |
| 44 | + assert.strictEqual(body, testResBody); |
48 | 45 | assert.ok('abcd' in res.headers); |
49 | | - countdown.dec(); |
| 46 | + server.close(); |
50 | 47 | }); |
51 | 48 | }); |
52 | 49 | }); |