• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6const assert = require('assert');
7const h2 = require('http2');
8const NGHTTP2_INTERNAL_ERROR = h2.constants.NGHTTP2_INTERNAL_ERROR;
9const Countdown = require('../common/countdown');
10
11const server = h2.createServer();
12
13// Do not mustCall the server side callbacks, they may or may not be called
14// depending on the OS. The determination is based largely on operating
15// system specific timings
16server.on('stream', (stream) => {
17  // Do not wrap in a must call or use common.expectsError (which now uses
18  // must call). The error may or may not be reported depending on operating
19  // system specific timings.
20  stream.on('error', (err) => {
21    assert.strictEqual(err.code, 'ERR_HTTP2_STREAM_ERROR');
22    assert.strictEqual(err.message,
23                       'Stream closed with error code NGHTTP2_INTERNAL_ERROR');
24  });
25  stream.respond();
26  stream.end();
27});
28
29server.listen(0, common.mustCall(() => {
30  const client = h2.connect(`http://localhost:${server.address().port}`);
31  const countdown = new Countdown(2, () => {
32    server.close();
33    client.close();
34  });
35  client.on('connect', () => countdown.dec());
36
37  const req = client.request();
38  req.destroy(new Error('test'));
39
40  req.on('error', common.expectsError({
41    name: 'Error',
42    message: 'test'
43  }));
44
45  req.on('close', common.mustCall(() => {
46    assert.strictEqual(req.rstCode, NGHTTP2_INTERNAL_ERROR);
47    assert.strictEqual(req.rstCode, NGHTTP2_INTERNAL_ERROR);
48    countdown.dec();
49  }));
50
51  req.on('response', common.mustNotCall());
52  req.resume();
53  req.on('end', common.mustNotCall());
54}));
55