1
- // Flags: --expose-internals
2
1
'use strict' ;
2
+
3
+ // This tests heap snapshot integration of http2.
4
+
3
5
const common = require ( '../common' ) ;
4
- const { recordState } = require ( '../common/heap' ) ;
6
+ const { createJSHeapSnapshot, validateByRetainingPath, validateByRetainingPathFromNodes } = require ( '../common/heap' ) ;
7
+ const assert = require ( 'assert' ) ;
8
+
5
9
if ( ! common . hasCrypto )
6
10
common . skip ( 'missing crypto' ) ;
7
11
const http2 = require ( 'http2' ) ;
8
12
13
+ // Before http2 is used, no Http2Session or Http2Streamshould be created.
9
14
{
10
- const state = recordState ( ) ;
11
- state . validateSnapshotNodes ( 'Node / Http2Session' , [ ] ) ;
12
- state . validateSnapshotNodes ( 'Node / Http2Stream' , [ ] ) ;
15
+ const sessions = validateByRetainingPath ( 'Node / Http2Session' , [ ] ) ;
16
+ assert . strictEqual ( sessions . length , 0 ) ;
17
+ const streams = validateByRetainingPath ( 'Node / Http2Stream' , [ ] ) ;
18
+ assert . strictEqual ( streams . length , 0 ) ;
13
19
}
14
20
15
21
const server = http2 . createServer ( ) ;
@@ -21,63 +27,45 @@ server.listen(0, () => {
21
27
const req = client . request ( ) ;
22
28
23
29
req . on ( 'response' , common . mustCall ( ( ) => {
24
- const state = recordState ( ) ;
30
+ const nodes = createJSHeapSnapshot ( ) ;
25
31
26
32
// `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 } ) ;
33
+ validateByRetainingPathFromNodes ( nodes , 'Node / Http2Stream' , [
34
+ // current_headers and/or queue could be empty
35
+ { node_name : 'Http2Stream' , edge_name : 'native_to_javascript' } ,
36
+ ] ) ;
35
37
36
38
// `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 } ) ;
39
+ validateByRetainingPathFromNodes ( nodes , 'Node / FileHandle' , [
40
+ { node_name : 'FileHandle' , edge_name : 'native_to_javascript' } ,
41
+ // current_headers could be empty
42
+ ] ) ;
43
+ validateByRetainingPathFromNodes ( nodes , 'Node / TCPSocketWrap' , [
44
+ { node_name : 'TCP' , edge_name : 'native_to_javascript' } ,
45
+ ] ) ;
46
+
47
+ validateByRetainingPathFromNodes ( nodes , 'Node / TCPServerWrap' , [
48
+ { node_name : 'TCP' , edge_name : 'native_to_javascript' } ,
49
+ ] ) ;
50
+
59
51
// `Node / StreamPipe` (C++) -> StreamPipe (JS)
60
- state . validateSnapshotNodes ( 'Node / StreamPipe' , [
61
- {
62
- children : [
63
- { node_name : 'StreamPipe' , edge_name : 'native_to_javascript' } ,
64
- ] ,
65
- } ,
52
+ validateByRetainingPathFromNodes ( nodes , 'Node / StreamPipe' , [
53
+ { node_name : 'StreamPipe' , edge_name : 'native_to_javascript' } ,
66
54
] ) ;
55
+
67
56
// `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 } ) ;
57
+ const sessions = validateByRetainingPathFromNodes ( nodes , 'Node / Http2Session' , [ ] ) ;
58
+ validateByRetainingPathFromNodes ( sessions , 'Node / Http2Session' , [
59
+ { node_name : 'Http2Session' , edge_name : 'native_to_javascript' } ,
60
+ ] ) ;
61
+ validateByRetainingPathFromNodes ( sessions , 'Node / Http2Session' , [
62
+ { node_name : 'Node / nghttp2_memory' , edge_name : 'nghttp2_memory' } ,
63
+ ] ) ;
64
+ validateByRetainingPathFromNodes ( sessions , 'Node / Http2Session' , [
65
+ { node_name : 'Node / streams' , edge_name : 'streams' } ,
66
+ ] ) ;
67
+ // outstanding_pings, outgoing_buffers, outgoing_storage,
68
+ // pending_rst_streams could be empty
81
69
} ) ) ;
82
70
83
71
req . resume ( ) ;
0 commit comments