summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-client-rststream-before-connect.js
blob: 33b6cb354fe225489c7f53f744c38d641fc49cca (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
// Flags: --expose-http2
'use strict';

const common = require('../common');
const assert = require('assert');
const h2 = require('http2');

const server = h2.createServer();

server.listen(0);

server.on('listening', common.mustCall(() => {

  const client = h2.connect(`http://localhost:${server.address().port}`);

  const req = client.request({ ':path': '/' });
  client.rstStream(req, 0);
  assert.strictEqual(req.rstCode, 0);

  // make sure that destroy is called
  req._destroy = common.mustCall(req._destroy.bind(req));

  req.on('streamClosed', common.mustCall((code) => {
    assert.strictEqual(req.destroyed, true);
    assert.strictEqual(code, 0);
    server.close();
    client.destroy();
  }));

  req.on('response', common.mustNotCall());
  req.resume();
  req.on('end', common.mustCall());
  req.end();
}));