Skip to content

Commit 8905be2

Browse files
committed
test: refactor test-http-information-processing
Replace magic numbers with constant. Use for loop for repeated code. Reduce console logging. Remove unneeded countdown module use. PR-URL: #32547 Reviewed-By: Anna Henningsen <anna@addaleax.net> Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
1 parent 867ff41 commit 8905be2

File tree

1 file changed

+12
-15
lines changed

1 file changed

+12
-15
lines changed

test/parallel/test-http-information-processing.js

+12-15
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,21 @@
22
require('../common');
33
const assert = require('assert');
44
const http = require('http');
5-
const Countdown = require('../common/countdown');
65

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;
98

109
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+
}
1514
console.error('Server sending full response...');
1615
res.writeHead(200, {
1716
'Content-Type': 'text/plain',
1817
'ABCD': '1'
1918
});
20-
res.end(test_res_body);
19+
res.end(testResBody);
2120
});
2221

2322
server.listen(0, function() {
@@ -29,24 +28,22 @@ server.listen(0, function() {
2928
console.error('Client sending request...');
3029

3130
let body = '';
31+
let infoCount = 0;
3232

33-
req.on('information', function(res) {
34-
console.error('Client got 102 Processing...');
35-
countdown.dec();
36-
});
33+
req.on('information', () => { infoCount++; });
3734

3835
req.on('response', function(res) {
3936
// Check that all 102 Processing received before full response received.
40-
assert.strictEqual(countdown.remaining, 1);
37+
assert.strictEqual(infoCount, kMessageCount);
4138
assert.strictEqual(res.statusCode, 200,
4239
`Final status code was ${res.statusCode}, not 200.`);
4340
res.setEncoding('utf8');
4441
res.on('data', function(chunk) { body += chunk; });
4542
res.on('end', function() {
4643
console.error('Got full response.');
47-
assert.strictEqual(body, test_res_body);
44+
assert.strictEqual(body, testResBody);
4845
assert.ok('abcd' in res.headers);
49-
countdown.dec();
46+
server.close();
5047
});
5148
});
5249
});

0 commit comments

Comments
 (0)