• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3// Tests opening 100 concurrent simultaneous uploading streams over a single
4// connection and makes sure that the data for each is appropriately echoed.
5
6const common = require('../common');
7if (!common.hasCrypto)
8  common.skip('missing crypto');
9const assert = require('assert');
10const http2 = require('http2');
11const Countdown = require('../common/countdown');
12
13const server = http2.createServer();
14
15const count = 100;
16
17server.on('stream', common.mustCall((stream) => {
18  stream.respond();
19  stream.pipe(stream);
20}, count));
21
22server.listen(0, common.mustCall(() => {
23  const client = http2.connect(`http://localhost:${server.address().port}`);
24  client.setMaxListeners(100);
25
26  const countdown = new Countdown(count, () => {
27    server.close();
28    client.close();
29  });
30
31  function doRequest() {
32    const req = client.request({ ':method': 'POST ' });
33
34    let data = '';
35    req.setEncoding('utf8');
36    req.on('data', (chunk) => data += chunk);
37    req.on('end', common.mustCall(() => {
38      assert.strictEqual(data, 'abcdefghij');
39    }));
40    req.on('close', common.mustCall(() => countdown.dec()));
41
42    let n = 0;
43    function writeChunk() {
44      if (n < 10) {
45        req.write(String.fromCharCode(97 + n));
46        setTimeout(writeChunk, 10);
47      } else {
48        req.end();
49      }
50      n++;
51    }
52
53    writeChunk();
54  }
55
56  for (let n = 0; n < count; n++)
57    doRequest();
58}));
59