summaryrefslogtreecommitdiff
path: root/test/parallel/test-http2-too-many-settings.js
blob: 4feda98c05d52267042c46b9d6dcd9609eb7969a (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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
'use strict';

// Tests that attempting to send too many non-acknowledged
// settings frames will result in a throw.

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

const maxPendingAck = 2;
const server = h2.createServer({ maxPendingAck: maxPendingAck + 1 });

let clients = 2;

function doTest(session) {
  for (let n = 0; n < maxPendingAck; n++)
    assert.doesNotThrow(() => session.settings({ enablePush: false }));
  assert.throws(() => session.settings({ enablePush: false }),
                common.expectsError({
                  code: 'ERR_HTTP2_MAX_PENDING_SETTINGS_ACK',
                  type: Error
                }));
}

server.on('stream', common.mustNotCall());

server.once('session', common.mustCall((session) => doTest(session)));

server.listen(0);

const closeServer = common.mustCall(() => {
  if (--clients === 0)
    server.close();
}, clients);

server.on('listening', common.mustCall(() => {
  const client = h2.connect(`http://localhost:${server.address().port}`,
                            { maxPendingAck: maxPendingAck + 1 });
  let remaining = maxPendingAck + 1;

  client.on('close', closeServer);
  client.on('localSettings', common.mustCall(() => {
    if (--remaining <= 0) {
      client.destroy();
    }
  }, maxPendingAck + 1));
  client.on('connect', common.mustCall(() => doTest(client)));
}));

// Setting maxPendingAck to 0, defaults it to 1
server.on('listening', common.mustCall(() => {
  const client = h2.connect(`http://localhost:${server.address().port}`,
                            { maxPendingAck: 0 });

  client.on('close', closeServer);
  client.on('localSettings', common.mustCall(() => {
    client.destroy();
  }));
}));