1717import * as api from '@opentelemetry/api' ;
1818import { hrTime } from '@opentelemetry/core' ;
1919import * as assert from 'assert' ;
20+ import * as sinon from 'sinon' ;
2021import { SumAggregator } from '../../src/aggregator' ;
2122import { AggregationTemporality } from '../../src/export/AggregationTemporality' ;
2223import { DataPointType } from '../../src/export/MetricData' ;
@@ -40,11 +41,17 @@ const cumulativeCollector1: MetricCollectorHandle = {
4041const sdkStartTime = hrTime ( ) ;
4142
4243describe ( 'TemporalMetricProcessor' , ( ) => {
44+ afterEach ( ( ) => {
45+ sinon . restore ( ) ;
46+ } ) ;
47+
4348 describe ( 'buildMetrics' , ( ) => {
4449 describe ( 'single delta collector' , ( ) => {
4550 const collectors = [ deltaCollector1 ] ;
4651
4752 it ( 'should build metrics' , ( ) => {
53+ const spy = sinon . spy ( deltaCollector1 , 'selectAggregationTemporality' ) ;
54+
4855 const aggregator = new SumAggregator ( ) ;
4956 const deltaMetricStorage = new DeltaMetricProcessor ( aggregator ) ;
5057 const temporalMetricStorage = new TemporalMetricProcessor ( aggregator ) ;
@@ -59,7 +66,10 @@ describe('TemporalMetricProcessor', () => {
5966 sdkStartTime ,
6067 hrTime ( ) ) ;
6168
62- assertMetricData ( metric , DataPointType . SINGULAR ) ;
69+ assertMetricData ( metric ,
70+ DataPointType . SINGULAR ,
71+ defaultInstrumentDescriptor ,
72+ AggregationTemporality . DELTA ) ;
6373 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
6474 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 1 ) ;
6575 }
@@ -74,7 +84,10 @@ describe('TemporalMetricProcessor', () => {
7484 sdkStartTime ,
7585 hrTime ( ) ) ;
7686
77- assertMetricData ( metric , DataPointType . SINGULAR ) ;
87+ assertMetricData ( metric ,
88+ DataPointType . SINGULAR ,
89+ defaultInstrumentDescriptor ,
90+ AggregationTemporality . DELTA ) ;
7891 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
7992 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 2 ) ;
8093 }
@@ -88,9 +101,15 @@ describe('TemporalMetricProcessor', () => {
88101 sdkStartTime ,
89102 hrTime ( ) ) ;
90103
91- assertMetricData ( metric , DataPointType . SINGULAR ) ;
104+ assertMetricData ( metric ,
105+ DataPointType . SINGULAR ,
106+ defaultInstrumentDescriptor ,
107+ AggregationTemporality . DELTA ) ;
92108 assert . strictEqual ( metric . dataPoints . length , 0 ) ;
93109 }
110+
111+ // selectAggregationTemporality should be called only once.
112+ assert . strictEqual ( spy . callCount , 1 ) ;
94113 } ) ;
95114 } ) ;
96115
@@ -112,7 +131,10 @@ describe('TemporalMetricProcessor', () => {
112131 sdkStartTime ,
113132 hrTime ( ) ) ;
114133
115- assertMetricData ( metric , DataPointType . SINGULAR ) ;
134+ assertMetricData ( metric ,
135+ DataPointType . SINGULAR ,
136+ defaultInstrumentDescriptor ,
137+ AggregationTemporality . DELTA ) ;
116138 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
117139 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 1 ) ;
118140 }
@@ -126,7 +148,10 @@ describe('TemporalMetricProcessor', () => {
126148 sdkStartTime ,
127149 hrTime ( ) ) ;
128150
129- assertMetricData ( metric , DataPointType . SINGULAR ) ;
151+ assertMetricData ( metric ,
152+ DataPointType . SINGULAR ,
153+ defaultInstrumentDescriptor ,
154+ AggregationTemporality . DELTA ) ;
130155 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
131156 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 1 ) ;
132157 }
@@ -136,6 +161,8 @@ describe('TemporalMetricProcessor', () => {
136161 describe ( 'single cumulative collector' , ( ) => {
137162 const collectors = [ cumulativeCollector1 ] ;
138163 it ( 'should build metrics' , ( ) => {
164+ const spy = sinon . spy ( cumulativeCollector1 , 'selectAggregationTemporality' ) ;
165+
139166 const aggregator = new SumAggregator ( ) ;
140167 const deltaMetricStorage = new DeltaMetricProcessor ( aggregator ) ;
141168 const temporalMetricStorage = new TemporalMetricProcessor ( aggregator ) ;
@@ -150,7 +177,10 @@ describe('TemporalMetricProcessor', () => {
150177 sdkStartTime ,
151178 hrTime ( ) ) ;
152179
153- assertMetricData ( metric , DataPointType . SINGULAR ) ;
180+ assertMetricData ( metric ,
181+ DataPointType . SINGULAR ,
182+ defaultInstrumentDescriptor ,
183+ AggregationTemporality . CUMULATIVE ) ;
154184 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
155185 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 1 ) ;
156186 }
@@ -165,10 +195,16 @@ describe('TemporalMetricProcessor', () => {
165195 sdkStartTime ,
166196 hrTime ( ) ) ;
167197
168- assertMetricData ( metric , DataPointType . SINGULAR ) ;
198+ assertMetricData ( metric ,
199+ DataPointType . SINGULAR ,
200+ defaultInstrumentDescriptor ,
201+ AggregationTemporality . CUMULATIVE ) ;
169202 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
170203 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 3 ) ;
171204 }
205+
206+ // selectAggregationTemporality should be called only once.
207+ assert . strictEqual ( spy . callCount , 1 ) ;
172208 } ) ;
173209 } ) ;
174210
@@ -189,7 +225,10 @@ describe('TemporalMetricProcessor', () => {
189225 sdkStartTime ,
190226 hrTime ( ) ) ;
191227
192- assertMetricData ( metric , DataPointType . SINGULAR ) ;
228+ assertMetricData ( metric ,
229+ DataPointType . SINGULAR ,
230+ defaultInstrumentDescriptor ,
231+ AggregationTemporality . CUMULATIVE ) ;
193232 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
194233 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 1 ) ;
195234 }
@@ -204,7 +243,10 @@ describe('TemporalMetricProcessor', () => {
204243 sdkStartTime ,
205244 hrTime ( ) ) ;
206245
207- assertMetricData ( metric , DataPointType . SINGULAR ) ;
246+ assertMetricData ( metric ,
247+ DataPointType . SINGULAR ,
248+ defaultInstrumentDescriptor ,
249+ AggregationTemporality . DELTA ) ;
208250 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
209251 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 3 ) ;
210252 }
@@ -217,7 +259,10 @@ describe('TemporalMetricProcessor', () => {
217259 sdkStartTime ,
218260 hrTime ( ) ) ;
219261
220- assertMetricData ( metric , DataPointType . SINGULAR ) ;
262+ assertMetricData ( metric ,
263+ DataPointType . SINGULAR ,
264+ defaultInstrumentDescriptor ,
265+ AggregationTemporality . CUMULATIVE ) ;
221266 assert . strictEqual ( metric . dataPoints . length , 1 ) ;
222267 assertDataPoint ( metric . dataPoints [ 0 ] , { } , 3 ) ;
223268 }
0 commit comments