0
0
mirror of https://github.com/nodejs/node.git synced 2024-11-29 23:16:30 +01:00
nodejs/test/sequential/test-http-regr-gh-2928.js
Gibson Fahnestock 3d2aef3979 test: s/assert.equal/assert.strictEqual/
Use assert.strictEqual instead of assert.equal in tests, manually
convert types where necessary.

PR-URL: https://github.com/nodejs/node/pull/10698
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Colin Ihrig <cjihrig@gmail.com>
Reviewed-By: Michael Dawson <michael_dawson@ca.ibm.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
Reviewed-By: Michaël Zasso <targos@protonmail.com>
Reviewed-By: Teddy Katz <teddy.katz@gmail.com>
2017-01-11 14:19:26 +00:00

64 lines
1.6 KiB
JavaScript

// This test is designed to fail with a segmentation fault in Node.js 4.1.0 and
// execute without issues in Node.js 4.1.1 and up.
'use strict';
const common = require('../common');
const assert = require('assert');
const httpCommon = require('_http_common');
const HTTPParser = process.binding('http_parser').HTTPParser;
const net = require('net');
const COUNT = httpCommon.parsers.max + 1;
const parsers = new Array(COUNT);
for (let i = 0; i < parsers.length; i++)
parsers[i] = httpCommon.parsers.alloc();
let gotRequests = 0;
let gotResponses = 0;
function execAndClose() {
if (parsers.length === 0)
return;
process.stdout.write('.');
const parser = parsers.pop();
parser.reinitialize(HTTPParser.RESPONSE);
const socket = net.connect(common.PORT);
socket.on('error', (e) => {
// If SmartOS and ECONNREFUSED, then retry. See
// https://github.com/nodejs/node/issues/2663.
if (common.isSunOS && e.code === 'ECONNREFUSED') {
parsers.push(parser);
socket.destroy();
setImmediate(execAndClose);
return;
}
throw e;
});
parser.consume(socket._handle._externalStream);
parser.onIncoming = function onIncoming() {
process.stdout.write('+');
gotResponses++;
parser.unconsume(socket._handle._externalStream);
httpCommon.freeParser(parser);
socket.destroy();
setImmediate(execAndClose);
};
}
const server = net.createServer(function(c) {
if (++gotRequests === COUNT)
server.close();
c.end('HTTP/1.1 200 OK\r\n\r\n', function() {
c.destroySoon();
});
}).listen(common.PORT, execAndClose);
process.on('exit', function() {
assert.strictEqual(gotResponses, COUNT);
});