2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2016-05-29 03:06:56 -04:00
|
|
|
require('../common');
|
2012-04-08 20:54:53 +05:30
|
|
|
|
2016-12-30 18:38:06 -05:00
|
|
|
const http = require('http');
|
2012-04-08 20:54:53 +05:30
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const server = http.createServer(function(req, res) {
|
2015-05-19 13:00:06 +02:00
|
|
|
res.writeHead(200, {'Content-Type': 'text/plain'});
|
|
|
|
res.end('OK');
|
2012-04-08 20:54:53 +05:30
|
|
|
});
|
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
const agent = new http.Agent({maxSockets: 1});
|
2012-04-08 20:54:53 +05:30
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, function() {
|
2012-04-08 20:54:53 +05:30
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
for (let i = 0; i < 11; ++i) {
|
2012-04-08 20:54:53 +05:30
|
|
|
createRequest().end();
|
|
|
|
}
|
|
|
|
|
2015-05-19 13:00:06 +02:00
|
|
|
function callback() {}
|
2012-04-08 20:54:53 +05:30
|
|
|
|
2017-01-08 13:19:00 +00:00
|
|
|
let count = 0;
|
2012-04-08 20:54:53 +05:30
|
|
|
|
|
|
|
function createRequest() {
|
2016-01-13 21:42:45 +01:00
|
|
|
const req = http.request(
|
2016-05-29 03:06:56 -04:00
|
|
|
{port: server.address().port, path: '/', agent: agent},
|
2016-01-13 21:42:45 +01:00
|
|
|
function(res) {
|
|
|
|
req.clearTimeout(callback);
|
|
|
|
|
|
|
|
res.on('end', function() {
|
|
|
|
count++;
|
|
|
|
|
2016-08-17 16:14:43 -07:00
|
|
|
if (count === 11) {
|
2016-01-13 21:42:45 +01:00
|
|
|
server.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
res.resume();
|
|
|
|
}
|
|
|
|
);
|
2012-04-08 20:54:53 +05:30
|
|
|
|
|
|
|
req.setTimeout(1000, callback);
|
|
|
|
return req;
|
|
|
|
}
|
|
|
|
});
|