Skip to content

Commit ac71d99

Browse files
apapirovskiMylesBorins
authored andcommitted
test: add http2 compat setTimeout tests
Add tests for Http2ServerRequest and Http2ServerResponse setTimeout PR-URL: #15156 Reviewed-By: Benjamin Gruenbaum <[email protected]> Reviewed-By: Luigi Pinca <[email protected]> Reviewed-By: James M Snell <[email protected]>
1 parent 7106734 commit ac71d99

2 files changed

+64
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const http2 = require('http2');
8+
9+
const server = http2.createServer();
10+
11+
server.on('request', (req, res) => {
12+
req.setTimeout(common.platformTimeout(1), common.mustCall(() => {
13+
res.end();
14+
}));
15+
});
16+
17+
server.listen(0, common.mustCall(() => {
18+
const port = server.address().port;
19+
const client = http2.connect(`http://localhost:${port}`);
20+
const req = client.request({
21+
':path': '/',
22+
':method': 'GET',
23+
':scheme': 'http',
24+
':authority': `localhost:${port}`
25+
});
26+
req.on('end', common.mustCall(() => {
27+
server.close();
28+
client.destroy();
29+
}));
30+
req.resume();
31+
req.end();
32+
}));
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
// Flags: --expose-http2
2+
'use strict';
3+
4+
const common = require('../common');
5+
if (!common.hasCrypto)
6+
common.skip('missing crypto');
7+
const http2 = require('http2');
8+
9+
const server = http2.createServer();
10+
11+
server.on('request', (req, res) => {
12+
res.setTimeout(common.platformTimeout(1), common.mustCall(() => {
13+
res.end();
14+
}));
15+
});
16+
17+
server.listen(0, common.mustCall(() => {
18+
const port = server.address().port;
19+
const client = http2.connect(`http://localhost:${port}`);
20+
const req = client.request({
21+
':path': '/',
22+
':method': 'GET',
23+
':scheme': 'http',
24+
':authority': `localhost:${port}`
25+
});
26+
req.on('end', common.mustCall(() => {
27+
server.close();
28+
client.destroy();
29+
}));
30+
req.resume();
31+
req.end();
32+
}));

0 commit comments

Comments
 (0)