forked from nodejs/node
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest-http-regr-gh-2928.js
More file actions
51 lines (43 loc) · 1.27 KB
/
test-http-regr-gh-2928.js
File metadata and controls
51 lines (43 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
'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 PARALLEL = 30;
const COUNT = httpCommon.parsers.max + 100;
const parsers = new Array(COUNT);
for (var i = 0; i < parsers.length; i++)
parsers[i] = httpCommon.parsers.alloc();
var gotRequests = 0;
var gotResponses = 0;
function execAndClose() {
process.stdout.write('.');
if (parsers.length === 0)
return;
const parser = parsers.pop();
parser.reinitialize(HTTPParser.RESPONSE);
const socket = net.connect(common.PORT);
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);
};
}
var 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, function() {
for (var i = 0; i < PARALLEL; i++)
execAndClose();
});
process.on('exit', function() {
assert.equal(gotResponses, COUNT);
});