2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2011-01-25 17:03:21 +01:00
|
|
|
var common = require('../common');
|
|
|
|
var assert = require('assert');
|
|
|
|
var http = require('http');
|
|
|
|
|
|
|
|
var expected = 10000;
|
|
|
|
var responses = 0;
|
|
|
|
var requests = 0;
|
|
|
|
var connection;
|
|
|
|
|
|
|
|
var server = http.Server(function(req, res) {
|
|
|
|
requests++;
|
|
|
|
assert.equal(req.connection, connection);
|
|
|
|
res.writeHead(200);
|
2011-10-05 00:08:18 +02:00
|
|
|
res.end('hello world\n');
|
2011-01-25 17:03:21 +01:00
|
|
|
});
|
|
|
|
|
|
|
|
server.once('connection', function(c) {
|
|
|
|
connection = c;
|
|
|
|
});
|
|
|
|
|
2015-06-19 20:45:30 +02:00
|
|
|
server.listen(common.PORT, function connect() {
|
2011-01-25 17:03:21 +01:00
|
|
|
var request = http.get({
|
|
|
|
port: common.PORT,
|
|
|
|
path: '/',
|
|
|
|
headers: {
|
|
|
|
'Connection': 'Keep-alive'
|
|
|
|
}
|
|
|
|
}, function(res) {
|
|
|
|
res.on('end', function() {
|
|
|
|
if (++responses < expected) {
|
2015-06-19 20:45:30 +02:00
|
|
|
connect();
|
2011-01-25 17:03:21 +01:00
|
|
|
} else {
|
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
2012-12-13 16:47:33 +01:00
|
|
|
res.resume();
|
2011-01-25 17:03:21 +01:00
|
|
|
}).on('error', function(e) {
|
|
|
|
console.log(e.message);
|
|
|
|
process.exit(1);
|
|
|
|
});
|
|
|
|
request.agent.maxSockets = 1;
|
|
|
|
});
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(expected, responses);
|
|
|
|
assert.equal(expected, requests);
|
|
|
|
});
|