• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2const common = require('../common');
3if (!common.hasCrypto)
4  common.skip('missing crypto');
5const http2 = require('http2');
6
7// Regression test for https://github.com/nodejs/node/issues/27416.
8// Check that received data is accounted for correctly in the maxSessionMemory
9// mechanism.
10
11const bodyLength = 8192;
12const maxSessionMemory = 1;  // 1 MiB
13const requestCount = 1000;
14
15const server = http2.createServer({ maxSessionMemory });
16server.on('stream', (stream) => {
17  stream.respond();
18  stream.end();
19});
20
21server.listen(common.mustCall(() => {
22  const client = http2.connect(`http://localhost:${server.address().port}`, {
23    maxSessionMemory
24  });
25
26  function request() {
27    return new Promise((resolve, reject) => {
28      const stream = client.request({
29        ':method': 'POST',
30        'content-length': bodyLength
31      });
32      stream.on('error', reject);
33      stream.on('response', resolve);
34      stream.end('a'.repeat(bodyLength));
35    });
36  }
37
38  (async () => {
39    for (let i = 0; i < requestCount; i++) {
40      await request();
41    }
42
43    client.close();
44    server.close();
45  })().then(common.mustCall());
46}));
47