test: refactor test-http-parser

Use common's mustCall (for some reason was implementing its own?), and
other small fixes.

PR-URL: https://github.com/nodejs/node/pull/18219
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Luigi Pinca <luigipinca@gmail.com>
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: Ruben Bridgewater <ruben@bridgewater.de>
This commit is contained in:
Jon Moss 2018-01-17 20:36:25 -05:00 committed by Ruben Bridgewater
parent f576341dc2
commit 5e17f54d79
No known key found for this signature in database
GPG Key ID: F07496B3EB3C1762

View File

@ -20,15 +20,11 @@
// USE OR OTHER DEALINGS IN THE SOFTWARE.
'use strict';
const common = require('../common');
const { mustCall, mustNotCall } = require('../common');
const assert = require('assert');
const binding = process.binding('http_parser');
const methods = binding.methods;
const HTTPParser = binding.HTTPParser;
const REQUEST = HTTPParser.REQUEST;
const RESPONSE = HTTPParser.RESPONSE;
const { methods, HTTPParser } = process.binding('http_parser');
const { REQUEST, RESPONSE } = HTTPParser;
const kOnHeaders = HTTPParser.kOnHeaders | 0;
const kOnHeadersComplete = HTTPParser.kOnHeadersComplete | 0;
@ -55,7 +51,7 @@ function newParser(type) {
parser[kOnHeadersComplete] = function() {
};
parser[kOnBody] = common.mustNotCall('kOnBody should not be called');
parser[kOnBody] = mustNotCall('kOnBody should not be called');
parser[kOnMessageComplete] = function() {
};
@ -64,21 +60,6 @@ function newParser(type) {
}
function mustCall(f, times) {
let actual = 0;
process.setMaxListeners(256);
process.on('exit', function() {
assert.strictEqual(actual, times || 1);
});
return function() {
actual++;
return f.apply(this, Array.prototype.slice.call(arguments));
};
}
function expectBody(expected) {
return mustCall(function(buf, start, len) {
const body = String(buf.slice(start, start + len));