@@ -559,16 +559,13 @@ describe("Histogram clearing support", () => {
559559} ) ;
560560
561561describe ( "WASM Histogram bucket size overflow" , ( ) => {
562- let wasmHistogram : Histogram ;
563562 beforeAll ( initWebAssembly ) ;
564- afterEach ( ( ) => wasmHistogram . destroy ( ) ) ;
565-
566563 [ 8 as const , 16 as const ] . forEach (
567564 ( bitBucketSize ) => {
568565 const maxBucketSize = ( 2 ** bitBucketSize ) - 1 ;
569566 it ( `should fail when recording more than ${ maxBucketSize } times the same value` , ( ) => {
570567 //given
571- wasmHistogram = build ( { useWebAssembly : true , bitBucketSize } ) ;
568+ const wasmHistogram = build ( { useWebAssembly : true , bitBucketSize } ) ;
572569
573570 //when //then
574571 try {
@@ -577,42 +574,37 @@ describe("WASM Histogram bucket size overflow", () => {
577574 wasmHistogram . recordValue ( 1 ) ;
578575 }
579576 fail ( `should have failed due to ${ bitBucketSize } bits integer overflow (bucket size : ${ i } )` ) ;
580- } catch ( e ) {
577+ } catch ( e ) {
581578 //ok
579+ } finally {
580+ wasmHistogram . destroy ( ) ;
582581 }
583582 } ) ;
584583
585- //Cannot use a destroyed histogram error
586- it . skip ( `should fail when adding two histograms when the same bucket count addition is greater than ${ bitBucketSize } bits max integer value` , ( ) => {
587- //given
588- const histogram1 = build ( { useWebAssembly : true , bitBucketSize } ) ;
589- histogram1 . recordValueWithCount ( 1 , maxBucketSize ) ;
590- const histogram2 = build ( { useWebAssembly : true , bitBucketSize } ) ;
591- histogram2 . recordValueWithCount ( 1 , maxBucketSize ) ;
592-
593- //when //then
594- try {
595- histogram2 . add ( histogram1 ) ;
596- fail ( `should have failed due to ${ bitBucketSize } bits integer overflow` ) ;
597- } catch ( e ) {
598- //ok
599- }
600- } ) ;
584+ it ( `should fail when adding two histograms when the same bucket count addition is greater than ${ bitBucketSize } bits max integer value` , ( ) => {
585+ //given
586+ const histogram1 = build ( { useWebAssembly : true , bitBucketSize } ) ;
587+ histogram1 . recordValueWithCount ( 1 , maxBucketSize ) ;
588+ const histogram2 = build ( { useWebAssembly : true , bitBucketSize } ) ;
589+ histogram2 . recordValueWithCount ( 1 , maxBucketSize ) ;
590+
591+ //when //then
592+ expect ( ( ) => histogram2 . add ( histogram1 ) ) . toThrow ( ) ;
593+
594+ histogram1 . destroy ( ) ;
595+ histogram2 . destroy ( ) ;
596+ } ) ;
601597 } ) ;
602- //Cannot use a destroyed histogram error
603- it . skip ( "should fail when decoding an Int32 histogram with one bucket count greater than 16bits" , ( ) => {
598+
599+ it ( "should fail when decoding an Int32 histogram with one bucket count greater than 16bits in a smaller histogram " , ( ) => {
604600 //given
605601 const int32Histogram = build ( { useWebAssembly : true , bitBucketSize : 32 } ) as WasmHistogram ;
606602 int32Histogram . recordValueWithCount ( 1 , 2 ** 32 - 1 ) ;
603+ const encodedInt32Histogram = int32Histogram . encodeIntoCompressedBase64 ( ) ;
607604
608605 //when //then
609- try {
610- const encodedInt32Histogram = int32Histogram . encodeIntoCompressedBase64 ( ) ;
611- decodeFromCompressedBase64 ( encodedInt32Histogram , 16 , true ) ;
612- fail ( `should have failed due to 16bits integer overflow` ) ;
613- } catch ( e ) {
614- //ok
615- }
606+ expect ( ( ) => decodeFromCompressedBase64 ( encodedInt32Histogram , 16 , true ) ) . toThrow ( ) ;
607+ int32Histogram . destroy ( ) ;
616608 } ) ;
617609} ) ;
618610
0 commit comments