2017-09-07 14:02:19 -04:00
|
|
|
'use strict';
|
|
|
|
|
|
|
|
const common = require('../common');
|
|
|
|
if (!common.hasCrypto)
|
|
|
|
common.skip('missing crypto');
|
2018-07-29 19:26:27 -07:00
|
|
|
const http2 = require('http2');
|
2017-09-07 14:02:19 -04:00
|
|
|
|
|
|
|
const serverTimeout = common.platformTimeout(200);
|
2017-09-16 08:56:42 -04:00
|
|
|
const mustNotCall = common.mustNotCall();
|
2017-09-07 14:02:19 -04:00
|
|
|
|
2018-07-29 19:26:27 -07:00
|
|
|
const server = http2.createServer();
|
2017-09-07 14:02:19 -04:00
|
|
|
server.timeout = serverTimeout;
|
|
|
|
|
|
|
|
server.on('request', (req, res) => res.end());
|
2017-09-16 08:56:42 -04:00
|
|
|
server.on('timeout', mustNotCall);
|
2017-09-07 14:02:19 -04:00
|
|
|
|
|
|
|
server.listen(0, common.mustCall(() => {
|
|
|
|
const port = server.address().port;
|
|
|
|
|
|
|
|
const url = `http://localhost:${port}`;
|
2018-07-29 19:26:27 -07:00
|
|
|
const client = http2.connect(url);
|
2018-05-10 20:45:44 -07:00
|
|
|
const startTime = process.hrtime();
|
|
|
|
makeReq();
|
2017-09-07 14:02:19 -04:00
|
|
|
|
2018-05-10 20:45:44 -07:00
|
|
|
function makeReq() {
|
2017-09-07 14:02:19 -04:00
|
|
|
const request = client.request({
|
|
|
|
':path': '/foobar',
|
|
|
|
':method': 'GET',
|
|
|
|
':scheme': 'http',
|
|
|
|
':authority': `localhost:${port}`,
|
|
|
|
});
|
2017-09-16 08:56:42 -04:00
|
|
|
request.resume();
|
2017-09-07 14:02:19 -04:00
|
|
|
request.end();
|
|
|
|
|
2017-09-16 08:56:42 -04:00
|
|
|
request.on('end', () => {
|
2018-05-10 20:45:44 -07:00
|
|
|
const diff = process.hrtime(startTime);
|
|
|
|
const milliseconds = (diff[0] * 1e3 + diff[1] / 1e6);
|
|
|
|
if (milliseconds < serverTimeout * 2) {
|
2018-09-24 05:54:57 -07:00
|
|
|
makeReq();
|
2017-09-16 08:56:42 -04:00
|
|
|
} else {
|
|
|
|
server.removeListener('timeout', mustNotCall);
|
|
|
|
server.close();
|
2018-05-10 20:45:44 -07:00
|
|
|
client.close();
|
2017-09-16 08:56:42 -04:00
|
|
|
}
|
|
|
|
});
|
2017-09-07 14:02:19 -04:00
|
|
|
}
|
|
|
|
}));
|