1717import * as sinon from 'sinon' ;
1818
1919import * as heapProfiler from '../src/heap-profiler' ;
20- import * as v8HeapProfiler from '../src/heap-profiler-bindings ' ;
20+ import * as inspectorHeapProfiler from '../src/heap-profiler-inspector ' ;
2121import { AllocationProfileNode } from '../src/v8-types' ;
2222
2323import {
@@ -32,14 +32,14 @@ const copy = require('deep-copy');
3232const assert = require ( 'assert' ) ;
3333
3434describe ( 'HeapProfiler' , ( ) => {
35- let startStub : sinon . SinonStub < [ number , number ] , void > ;
36- let stopStub : sinon . SinonStub < [ ] , void > ;
37- let profileStub : sinon . SinonStub < [ ] , AllocationProfileNode > ;
35+ let startStub : sinon . SinonStub < [ number , number ] , Promise < void > > ;
36+ let stopStub : sinon . SinonStub < [ ] , Promise < void > > ;
37+ let profileStub : sinon . SinonStub < [ ] , Promise < AllocationProfileNode > > ;
3838 let dateStub : sinon . SinonStub < [ ] , number > ;
3939 let memoryUsageStub : sinon . SinonStub < [ ] , NodeJS . MemoryUsage > ;
4040 beforeEach ( ( ) => {
41- startStub = sinon . stub ( v8HeapProfiler , 'startSamplingHeapProfiler' ) ;
42- stopStub = sinon . stub ( v8HeapProfiler , 'stopSamplingHeapProfiler' ) ;
41+ startStub = sinon . stub ( inspectorHeapProfiler , 'startSamplingHeapProfiler' ) ;
42+ stopStub = sinon . stub ( inspectorHeapProfiler , 'stopSamplingHeapProfiler' ) ;
4343 dateStub = sinon . stub ( Date , 'now' ) . returns ( 0 ) ;
4444 } ) ;
4545
@@ -54,7 +54,7 @@ describe('HeapProfiler', () => {
5454 describe ( 'profile' , ( ) => {
5555 it ( 'should return a profile equal to the expected profile when external memory is allocated' , async ( ) => {
5656 profileStub = sinon
57- . stub ( v8HeapProfiler , 'getAllocationProfile' )
57+ . stub ( inspectorHeapProfiler , 'getAllocationProfile' )
5858 . returns ( copy ( v8HeapProfile ) ) ;
5959 memoryUsageStub = sinon . stub ( process , 'memoryUsage' ) . returns ( {
6060 external : 1024 ,
@@ -66,13 +66,13 @@ describe('HeapProfiler', () => {
6666 const intervalBytes = 1024 * 512 ;
6767 const stackDepth = 32 ;
6868 heapProfiler . start ( intervalBytes , stackDepth ) ;
69- const profile = heapProfiler . profile ( ) ;
69+ const profile = await heapProfiler . profile ( ) ;
7070 assert . deepEqual ( heapProfileWithExternal , profile ) ;
7171 } ) ;
7272
7373 it ( 'should return a profile equal to the expected profile when including all samples' , async ( ) => {
7474 profileStub = sinon
75- . stub ( v8HeapProfiler , 'getAllocationProfile' )
75+ . stub ( inspectorHeapProfiler , 'getAllocationProfile' )
7676 . returns ( copy ( v8HeapWithPathProfile ) ) ;
7777 memoryUsageStub = sinon . stub ( process , 'memoryUsage' ) . returns ( {
7878 external : 0 ,
@@ -84,13 +84,13 @@ describe('HeapProfiler', () => {
8484 const intervalBytes = 1024 * 512 ;
8585 const stackDepth = 32 ;
8686 heapProfiler . start ( intervalBytes , stackDepth ) ;
87- const profile = heapProfiler . profile ( ) ;
87+ const profile = await heapProfiler . profile ( ) ;
8888 assert . deepEqual ( heapProfileIncludePath , profile ) ;
8989 } ) ;
9090
9191 it ( 'should return a profile equal to the expected profile when excluding profiler samples' , async ( ) => {
9292 profileStub = sinon
93- . stub ( v8HeapProfiler , 'getAllocationProfile' )
93+ . stub ( inspectorHeapProfiler , 'getAllocationProfile' )
9494 . returns ( copy ( v8HeapWithPathProfile ) ) ;
9595 memoryUsageStub = sinon . stub ( process , 'memoryUsage' ) . returns ( {
9696 external : 0 ,
@@ -102,14 +102,14 @@ describe('HeapProfiler', () => {
102102 const intervalBytes = 1024 * 512 ;
103103 const stackDepth = 32 ;
104104 heapProfiler . start ( intervalBytes , stackDepth ) ;
105- const profile = heapProfiler . profile ( '@google-cloud/profiler' ) ;
105+ const profile = await heapProfiler . profile ( '@google-cloud/profiler' ) ;
106106 assert . deepEqual ( heapProfileExcludePath , profile ) ;
107107 } ) ;
108108
109109 it ( 'should throw error when not started' , ( ) => {
110- assert . throws (
111- ( ) => {
112- heapProfiler . profile ( ) ;
110+ assert . rejects (
111+ async ( ) => {
112+ await heapProfiler . profile ( ) ;
113113 } ,
114114 ( err : Error ) => {
115115 return err . message === 'Heap profiler is not enabled.' ;
@@ -122,9 +122,9 @@ describe('HeapProfiler', () => {
122122 const stackDepth = 32 ;
123123 heapProfiler . start ( intervalBytes , stackDepth ) ;
124124 heapProfiler . stop ( ) ;
125- assert . throws (
126- ( ) => {
127- heapProfiler . profile ( ) ;
125+ assert . rejects (
126+ async ( ) => {
127+ await heapProfiler . profile ( ) ;
128128 } ,
129129 ( err : Error ) => {
130130 return err . message === 'Heap profiler is not enabled.' ;
@@ -160,7 +160,7 @@ describe('HeapProfiler', () => {
160160 assert . strictEqual (
161161 e . message ,
162162 'Heap profiler is already started with intervalBytes 524288 and' +
163- ' stackDepth 64 '
163+ ' stackDepth 128 '
164164 ) ;
165165 }
166166 assert . ok (
0 commit comments