• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1// Flags: --expose-internals
2'use strict';
3const common = require('../common');
4const { recordState } = require('../common/heap');
5if (!common.hasCrypto)
6  common.skip('missing crypto');
7const http2 = require('http2');
8
9{
10  const state = recordState();
11  state.validateSnapshotNodes('Node / Http2Session', []);
12  state.validateSnapshotNodes('Node / Http2Stream', []);
13}
14
15const server = http2.createServer();
16server.on('stream', (stream) => {
17  stream.respondWithFile(process.execPath);
18});
19server.listen(0, () => {
20  const client = http2.connect(`http://localhost:${server.address().port}`);
21  const req = client.request();
22
23  req.on('response', common.mustCall(() => {
24    const state = recordState();
25
26    // `Node / Http2Stream` (C++) -> Http2Stream (JS)
27    state.validateSnapshotNodes('Node / Http2Stream', [
28      {
29        children: [
30          // current_headers and/or queue could be empty
31          { node_name: 'Http2Stream', edge_name: 'native_to_javascript' },
32        ],
33      },
34    ], { loose: true });
35
36    // `Node / FileHandle` (C++) -> FileHandle (JS)
37    state.validateSnapshotNodes('Node / FileHandle', [
38      {
39        children: [
40          { node_name: 'FileHandle', edge_name: 'native_to_javascript' },
41          // current_headers could be empty
42        ],
43      },
44    ], { loose: true });
45    state.validateSnapshotNodes('Node / TCPSocketWrap', [
46      {
47        children: [
48          { node_name: 'TCP', edge_name: 'native_to_javascript' },
49        ],
50      },
51    ], { loose: true });
52    state.validateSnapshotNodes('Node / TCPServerWrap', [
53      {
54        children: [
55          { node_name: 'TCP', edge_name: 'native_to_javascript' },
56        ],
57      },
58    ], { loose: true });
59    // `Node / StreamPipe` (C++) -> StreamPipe (JS)
60    state.validateSnapshotNodes('Node / StreamPipe', [
61      {
62        children: [
63          { node_name: 'StreamPipe', edge_name: 'native_to_javascript' },
64        ],
65      },
66    ]);
67    // `Node / Http2Session` (C++) -> Http2Session (JS)
68    state.validateSnapshotNodes('Node / Http2Session', [
69      {
70        children: [
71          { node_name: 'Http2Session', edge_name: 'native_to_javascript' },
72          { node_name: 'Node / nghttp2_memory', edge_name: 'nghttp2_memory' },
73          {
74            node_name: 'Node / streams', edge_name: 'streams',
75          },
76          // outstanding_pings, outgoing_buffers, outgoing_storage,
77          // pending_rst_streams could be empty
78        ],
79      },
80    ], { loose: true });
81  }));
82
83  req.resume();
84  req.on('end', common.mustCall(() => {
85    client.close();
86    server.close();
87  }));
88  req.end();
89});
90