1'use strict';
2
3const common = require('../common');
4if (!common.hasCrypto)
5  common.skip('missing crypto');
6const assert = require('assert');
7const http2 = require('http2');
8
9const server = http2.createServer();
10
11server.on('stream', common.mustCall((stream) => {
12  const session = stream.session;
13  session.goaway(1);
14  session.goaway(2);
15  stream.session.on('close', common.mustCall(() => {
16    assert.throws(
17      () => session.goaway(3),
18      {
19        code: 'ERR_HTTP2_INVALID_SESSION',
20        name: 'Error'
21      }
22    );
23  }));
24}));
25
26server.listen(0, common.mustCall(() => {
27  const client = http2.connect(`http://localhost:${server.address().port}`);
28  client.on('error', common.expectsError({
29    code: 'ERR_HTTP2_SESSION_ERROR'
30  }));
31
32  const req = client.request();
33  req.on('error', common.expectsError({
34    code: 'ERR_HTTP2_SESSION_ERROR'
35  }));
36  req.resume();
37  req.on('close', common.mustCall(() => {
38    server.close();
39    client.close();
40  }));
41}));
42