summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-many-writes-and-destroy.js
blob: 78db76e001cd3a24860853ba0248e61f65177639 (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
'use strict';

const common = require('../common');
if (!common.hasCrypto)
  common.skip('missing crypto');
const http2 = require('http2');

{
  const server = http2.createServer((req, res) => {
    req.pipe(res);
  });

  server.listen(0, () => {
    const url = `http://localhost:${server.address().port}`;
    const client = http2.connect(url);
    const req = client.request({ ':method': 'POST' });

    for (let i = 0; i < 4000; i++) {
      req.write(Buffer.alloc(6));
    }

    req.on('close', common.mustCall(() => {
      console.log('(req onclose)');
      server.close();
      client.close();
    }));

    req.once('data', common.mustCall(() => req.destroy()));
  });
}