Skip to content

Commit 8a0ecf4

Browse files
TrottBethGriggs
authored andcommitted
test: refactor test-http-expect-continue
Use common.mustCall() where appropriate. Remove some logic that is not required when common.mustCall() is used (incrementor/decrementor to make sure everything is called the same number of times). PR-URL: #19625 Reviewed-By: Gireesh Punathil <[email protected]> Reviewed-By: Trivikram Kamat <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 8afbd5c commit 8a0ecf4

File tree

1 file changed

+20
-27
lines changed

1 file changed

+20
-27
lines changed

test/parallel/test-http-expect-continue.js

+20-27
Original file line numberDiff line numberDiff line change
@@ -20,70 +20,63 @@
2020
// USE OR OTHER DEALINGS IN THE SOFTWARE.
2121

2222
'use strict';
23-
require('../common');
23+
const common = require('../common');
2424
const assert = require('assert');
2525
const http = require('http');
2626

27-
let outstanding_reqs = 0;
2827
const test_req_body = 'some stuff...\n';
2928
const test_res_body = 'other stuff!\n';
3029
let sent_continue = false;
3130
let got_continue = false;
3231

33-
function handler(req, res) {
34-
assert.strictEqual(sent_continue, true,
35-
'Full response sent before 100 Continue');
32+
const handler = common.mustCall((req, res) => {
33+
assert.ok(sent_continue, 'Full response sent before 100 Continue');
3634
console.error('Server sending full response...');
3735
res.writeHead(200, {
3836
'Content-Type': 'text/plain',
3937
'ABCD': '1'
4038
});
4139
res.end(test_res_body);
42-
}
40+
});
4341

44-
const server = http.createServer(handler);
45-
server.on('checkContinue', function(req, res) {
42+
const server = http.createServer();
43+
server.on('checkContinue', common.mustCall((req, res) => {
4644
console.error('Server got Expect: 100-continue...');
4745
res.writeContinue();
4846
sent_continue = true;
4947
setTimeout(function() {
5048
handler(req, res);
5149
}, 100);
52-
});
50+
}));
5351
server.listen(0);
5452

5553

56-
server.on('listening', function() {
54+
server.on('listening', common.mustCall(() => {
5755
const req = http.request({
58-
port: this.address().port,
56+
port: server.address().port,
5957
method: 'POST',
6058
path: '/world',
6159
headers: { 'Expect': '100-continue' }
6260
});
6361
console.error('Client sending request...');
64-
outstanding_reqs++;
6562
let body = '';
66-
req.on('continue', function() {
63+
req.on('continue', common.mustCall(() => {
6764
console.error('Client got 100 Continue...');
6865
got_continue = true;
6966
req.end(test_req_body);
70-
});
71-
req.on('response', function(res) {
72-
assert.strictEqual(got_continue, true,
73-
'Full response received before 100 Continue');
67+
}));
68+
req.on('response', common.mustCall((res) => {
69+
assert.ok(got_continue, 'Full response received before 100 Continue');
7470
assert.strictEqual(200, res.statusCode,
7571
`Final status code was ${res.statusCode}, not 200.`);
7672
res.setEncoding('utf8');
7773
res.on('data', function(chunk) { body += chunk; });
78-
res.on('end', function() {
74+
res.on('end', common.mustCall(() => {
7975
console.error('Got full response.');
80-
assert.strictEqual(body, test_res_body, 'Response body doesn\'t match.');
76+
assert.strictEqual(body, test_res_body);
8177
assert.ok('abcd' in res.headers, 'Response headers missing.');
82-
outstanding_reqs--;
83-
if (outstanding_reqs === 0) {
84-
server.close();
85-
process.exit();
86-
}
87-
});
88-
});
89-
});
78+
server.close();
79+
process.exit();
80+
}));
81+
}));
82+
}));

0 commit comments

Comments
 (0)