summaryrefslogtreecommitdiff
path: root/test/pummel/test-heapdump-http2.js
blob: b3d819edaef91afab3c0672f9aa3cc67c85b5236 (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
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
// Flags: --expose-internals
'use strict';
const common = require('../common');
const { recordState } = require('../common/heap');
if (!common.hasCrypto)
  common.skip('missing crypto');
const http2 = require('http2');

{
  const state = recordState();
  state.validateSnapshotNodes('Node / Http2Session', []);
  state.validateSnapshotNodes('Node / Http2Stream', []);
}

const server = http2.createServer();
server.on('stream', (stream) => {
  stream.respondWithFile(__filename);
});
server.listen(0, () => {
  const client = http2.connect(`http://localhost:${server.address().port}`);
  const req = client.request();

  req.on('response', common.mustCall(() => {
    const state = recordState();

    // `Node / Http2Stream` (C++) -> Http2Stream (JS)
    state.validateSnapshotNodes('Node / Http2Stream', [
      {
        children: [
          // current_headers and/or queue could be empty
          { node_name: 'Http2Stream', edge_name: 'wrapped' }
        ]
      },
    ], { loose: true });

    // `Node / FileHandle` (C++) -> FileHandle (JS)
    state.validateSnapshotNodes('Node / FileHandle', [
      {
        children: [
          { node_name: 'FileHandle', edge_name: 'wrapped' }
          // current_headers could be empty
        ]
      }
    ], { loose: true });
    state.validateSnapshotNodes('Node / TCPSocketWrap', [
      {
        children: [
          { node_name: 'TCP', edge_name: 'wrapped' }
        ]
      }
    ], { loose: true });
    state.validateSnapshotNodes('Node / TCPServerWrap', [
      {
        children: [
          { node_name: 'TCP', edge_name: 'wrapped' }
        ]
      }
    ], { loose: true });
    // `Node / StreamPipe` (C++) -> StreamPipe (JS)
    state.validateSnapshotNodes('Node / StreamPipe', [
      {
        children: [
          { node_name: 'StreamPipe', edge_name: 'wrapped' }
        ]
      }
    ]);
    // `Node / Http2Session` (C++) -> Http2Session (JS)
    state.validateSnapshotNodes('Node / Http2Session', [
      {
        children: [
          { node_name: 'Http2Session', edge_name: 'wrapped' },
          { node_name: 'Node / nghttp2_memory', edge_name: 'nghttp2_memory' },
          {
            node_name: 'Node / streams', edge_name: 'streams'
          }
          // outstanding_pings, outgoing_buffers, outgoing_storage,
          // pending_rst_streams could be empty
        ]
      }
    ], { loose: true });
  }));

  req.resume();
  req.on('end', common.mustCall(() => {
    client.close();
    server.close();
  }));
  req.end();
});