@@ -200,6 +200,7 @@ describe('BaseView', () => {
200200 const measurementValues = [ 1.1 , 2.3 , 3.2 , 4.3 , 5.2 ] ;
201201 const buckets = [ 2 , 4 , 6 ] ;
202202 const tags : Tags = { testKey1 : 'testValue' , testKey2 : 'testValue' } ;
203+ const tags1 : Tags = { testKey1 : 'testValue1' , testKey2 : 'testValue1' } ;
203204
204205 after ( ( ) => {
205206 process . hrtime = hrtime ;
@@ -277,7 +278,7 @@ describe('BaseView', () => {
277278 view . recordMeasurement ( measurement ) ;
278279 }
279280
280- it ( 'should has point' , ( ) => {
281+ it ( 'should have point' , ( ) => {
281282 const { timeseries} = view . getMetric ( ) ;
282283 const [ { points} ] = timeseries ;
283284 assert . ok ( points ) ;
@@ -299,6 +300,70 @@ describe('BaseView', () => {
299300 } ) ;
300301 } ) ;
301302
303+ describe (
304+ 'DISTRIBUTION aggregation type: record with measurements in succession from a single view and single measure' ,
305+ ( ) => {
306+ const view : View = new BaseView (
307+ 'test/view/name' , measure , AggregationType . DISTRIBUTION ,
308+ [ 'testKey1' , 'testKey2' ] , 'description test' , buckets ) ;
309+ let total = 0 ;
310+ for ( const value of measurementValues ) {
311+ total += value ;
312+ const measurement = { measure, tags, value} ;
313+ const measurement1 = { measure, tags : tags1 , value} ;
314+ view . recordMeasurement ( measurement ) ;
315+ view . recordMeasurement ( measurement1 ) ;
316+ }
317+
318+ it ( 'should have points' , ( ) => {
319+ const { timeseries} = view . getMetric ( ) ;
320+ assert . equal ( timeseries . length , 2 ) ;
321+ const [ { labelValues : labelValues1 , points : points1 } , {
322+ labelValues : labelValues2 ,
323+ points : points2
324+ } ] = timeseries ;
325+ assert . ok ( points1 ) ;
326+
327+ let [ point ] = points1 ;
328+ let { timestamp, value} = point ;
329+ assert . ok ( timestamp ) ;
330+ assert . equal ( typeof timestamp . nanos , 'number' ) ;
331+ assert . strictEqual ( timestamp . nanos , 1e7 ) ;
332+ assert . equal ( typeof timestamp . seconds , 'number' ) ;
333+ assert . strictEqual ( timestamp . seconds , 1000 ) ;
334+ assert . notEqual ( typeof value , 'number' ) ;
335+ assert . deepStrictEqual ( ( value as DistributionValue ) , {
336+ bucketOptions : { explicit : { bounds : buckets } } ,
337+ buckets : [ 1 , 2 , 2 , 0 ] ,
338+ count : 5 ,
339+ sum : total ,
340+ sumOfSquaredDeviation : 10.427999999999997
341+ } ) ;
342+ assert . deepEqual (
343+ labelValues1 , [ { 'value' : 'testValue' } , { 'value' : 'testValue' } ] ) ;
344+
345+ assert . ok ( points2 ) ;
346+ [ point ] = points2 ;
347+ ( { timestamp, value} = point ) ;
348+ assert . ok ( timestamp ) ;
349+ assert . equal ( typeof timestamp . nanos , 'number' ) ;
350+ assert . strictEqual ( timestamp . nanos , 1e7 ) ;
351+ assert . equal ( typeof timestamp . seconds , 'number' ) ;
352+ assert . strictEqual ( timestamp . seconds , 1000 ) ;
353+ assert . notEqual ( typeof value , 'number' ) ;
354+ assert . deepStrictEqual ( ( value as DistributionValue ) , {
355+ bucketOptions : { explicit : { bounds : buckets } } ,
356+ buckets : [ 1 , 2 , 2 , 0 ] ,
357+ count : 5 ,
358+ sum : total ,
359+ sumOfSquaredDeviation : 10.427999999999997
360+ } ) ;
361+ assert . deepEqual (
362+ labelValues2 ,
363+ [ { 'value' : 'testValue1' } , { 'value' : 'testValue1' } ] ) ;
364+ } ) ;
365+ } ) ;
366+
302367 describe ( 'COUNT aggregation type' , ( ) => {
303368 const view : View = new BaseView (
304369 'test/view/name' , measure , AggregationType . COUNT ,
@@ -308,7 +373,7 @@ describe('BaseView', () => {
308373 view . recordMeasurement ( measurement ) ;
309374 }
310375
311- it ( 'should has point' , ( ) => {
376+ it ( 'should have point' , ( ) => {
312377 const { timeseries} = view . getMetric ( ) ;
313378 const [ { points} ] = timeseries ;
314379 assert . ok ( points ) ;
@@ -335,7 +400,7 @@ describe('BaseView', () => {
335400 view . recordMeasurement ( measurement ) ;
336401 }
337402
338- it ( 'should has point' , ( ) => {
403+ it ( 'should have point' , ( ) => {
339404 const { timeseries} = view . getMetric ( ) ;
340405 const [ { points} ] = timeseries ;
341406 assert . ok ( points ) ;
@@ -360,7 +425,7 @@ describe('BaseView', () => {
360425 view . recordMeasurement ( measurement ) ;
361426 }
362427
363- it ( 'should has point' , ( ) => {
428+ it ( 'should have point' , ( ) => {
364429 const { timeseries} = view . getMetric ( ) ;
365430 const [ { points} ] = timeseries ;
366431 assert . ok ( points ) ;
0 commit comments