2015-05-19 13:00:06 +02:00
|
|
|
'use strict';
|
2015-11-24 20:59:49 -08:00
|
|
|
const common = require('../common');
|
|
|
|
const assert = require('assert');
|
|
|
|
const http = require('http');
|
2012-05-21 00:31:28 +02:00
|
|
|
|
|
|
|
var ntimeouts = 0;
|
|
|
|
var nchunks = 0;
|
|
|
|
|
|
|
|
process.on('exit', function() {
|
|
|
|
assert.equal(ntimeouts, 1);
|
|
|
|
assert.equal(nchunks, 2);
|
|
|
|
});
|
|
|
|
|
2015-11-24 20:59:49 -08:00
|
|
|
const options = {
|
2012-05-21 00:31:28 +02:00
|
|
|
method: 'GET',
|
2016-05-29 03:06:56 -04:00
|
|
|
port: undefined,
|
2012-05-21 00:31:28 +02:00
|
|
|
host: '127.0.0.1',
|
|
|
|
path: '/'
|
|
|
|
};
|
|
|
|
|
2015-11-24 20:59:49 -08:00
|
|
|
const server = http.createServer(function(req, res) {
|
2016-05-04 22:20:27 -07:00
|
|
|
res.writeHead(200, {'Content-Length': '2'});
|
2012-05-21 00:31:28 +02:00
|
|
|
res.write('*');
|
2015-11-24 20:59:49 -08:00
|
|
|
setTimeout(function() { res.end('*'); }, common.platformTimeout(100));
|
2012-05-21 00:31:28 +02:00
|
|
|
});
|
|
|
|
|
2016-05-29 03:06:56 -04:00
|
|
|
server.listen(0, options.host, function() {
|
|
|
|
options.port = this.address().port;
|
2015-11-24 20:59:49 -08:00
|
|
|
const req = http.request(options, onresponse);
|
2012-05-21 00:31:28 +02:00
|
|
|
req.end();
|
|
|
|
|
|
|
|
function onresponse(res) {
|
2013-01-07 16:00:10 +01:00
|
|
|
req.setTimeout(50, function() {
|
2012-05-21 00:31:28 +02:00
|
|
|
assert.equal(nchunks, 1); // should have received the first chunk by now
|
|
|
|
ntimeouts++;
|
|
|
|
});
|
|
|
|
|
|
|
|
res.on('data', function(data) {
|
|
|
|
assert.equal('' + data, '*');
|
|
|
|
nchunks++;
|
|
|
|
});
|
|
|
|
|
|
|
|
res.on('end', function() {
|
|
|
|
assert.equal(nchunks, 2);
|
|
|
|
server.close();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|