blob: a7c6184442aabc0d1db52b75757a5c6d33d7e8f6 (
plain)
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
|
// Flags: --expose-http2
'use strict';
const common = require('../common');
if (!common.hasCrypto)
common.skip('missing crypto');
const h2 = require('http2');
const serverTimeout = common.platformTimeout(200);
const callTimeout = common.platformTimeout(20);
const minRuns = Math.ceil(serverTimeout / callTimeout) * 2;
const mustNotCall = common.mustNotCall();
const server = h2.createServer();
server.timeout = serverTimeout;
server.on('request', (req, res) => res.end());
server.on('timeout', mustNotCall);
server.listen(0, common.mustCall(() => {
const port = server.address().port;
const url = `http://localhost:${port}`;
const client = h2.connect(url);
makeReq(minRuns);
function makeReq(attempts) {
const request = client.request({
':path': '/foobar',
':method': 'GET',
':scheme': 'http',
':authority': `localhost:${port}`,
});
request.resume();
request.end();
request.on('end', () => {
if (attempts) {
setTimeout(() => makeReq(attempts - 1), callTimeout);
} else {
server.removeListener('timeout', mustNotCall);
client.destroy();
server.close();
}
});
}
}));
|