• 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 http2 = require('http2');
8const Countdown = require('../common/countdown');
9
10const server = http2.createServer();
11const largeBuffer = Buffer.alloc(1e4);
12
13// Verify that a dependency cycle may exist, but that it doesn't crash anything
14
15server.on('stream', common.mustCall((stream) => {
16  stream.respond();
17  setImmediate(() => {
18    stream.end(largeBuffer);
19  });
20}, 3));
21server.on('session', common.mustCall((session) => {
22  session.on('priority', (id, parent, weight, exclusive) => {
23    assert.strictEqual(weight, 16);
24    assert.strictEqual(exclusive, false);
25    switch (id) {
26      case 1:
27        assert.strictEqual(parent, 5);
28        break;
29      case 3:
30        assert.strictEqual(parent, 1);
31        break;
32      case 5:
33        assert.strictEqual(parent, 3);
34        break;
35      default:
36        assert.fail('should not happen');
37    }
38  });
39}));
40
41server.listen(0, common.mustCall(() => {
42  const client = http2.connect(`http://localhost:${server.address().port}`);
43
44  const countdown = new Countdown(3, () => {
45    client.close();
46    server.close();
47  });
48
49  {
50    const req = client.request();
51    req.priority({ parent: 5 });
52    req.resume();
53    req.on('close', () => countdown.dec());
54  }
55
56  {
57    const req = client.request();
58    req.priority({ parent: 1 });
59    req.resume();
60    req.on('close', () => countdown.dec());
61  }
62
63  {
64    const req = client.request();
65    req.priority({ parent: 3 });
66    req.resume();
67    req.on('close', () => countdown.dec());
68  }
69}));
70