@@ -218,22 +218,25 @@ mod tests {
218
218
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
219
219
async fn updown_counter_aggregation_cumulative ( ) {
220
220
// Run this test with stdout enabled to see output.
221
- // cargo test counter_aggregation_cumulative --features=metrics,testing -- --nocapture
221
+ // cargo test updown_counter_aggregation_cumulative --features=metrics,testing -- --nocapture
222
222
updown_counter_aggregation_helper ( Temporality :: Cumulative ) ;
223
223
}
224
224
225
225
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
226
226
async fn updown_counter_aggregation_delta ( ) {
227
227
// Run this test with stdout enabled to see output.
228
- // cargo test counter_aggregation_delta --features=metrics,testing -- --nocapture
228
+ // cargo test updown_counter_aggregation_delta --features=metrics,testing -- --nocapture
229
229
updown_counter_aggregation_helper ( Temporality :: Delta ) ;
230
230
}
231
231
232
232
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
233
233
async fn gauge_aggregation ( ) {
234
234
// Run this test with stdout enabled to see output.
235
235
// cargo test gauge_aggregation --features=metrics,testing -- --nocapture
236
- gauge_aggregation_helper ( ) ;
236
+
237
+ // Gauge should use last value aggregation regardless of the aggregation temporality used.
238
+ gauge_aggregation_helper ( Temporality :: Delta ) ;
239
+ gauge_aggregation_helper ( Temporality :: Cumulative ) ;
237
240
}
238
241
239
242
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
@@ -1190,9 +1193,9 @@ mod tests {
1190
1193
}
1191
1194
}
1192
1195
1193
- fn gauge_aggregation_helper ( ) {
1196
+ fn gauge_aggregation_helper ( temporality : Temporality ) {
1194
1197
// Arrange
1195
- let mut test_context = TestContext :: new ( Temporality :: Delta ) ;
1198
+ let mut test_context = TestContext :: new ( temporality ) ;
1196
1199
let gauge = test_context. meter ( ) . i64_gauge ( "my_gauge" ) . init ( ) ;
1197
1200
1198
1201
// Act
@@ -1330,15 +1333,15 @@ mod tests {
1330
1333
let counter = test_context. i64_up_down_counter ( "test" , "my_updown_counter" , None ) ;
1331
1334
1332
1335
// Act
1333
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1334
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1335
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1336
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1336
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1337
+ counter. add ( - 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1338
+ counter. add ( - 5 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1339
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1337
1340
counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1338
1341
1339
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1340
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1341
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1342
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1343
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1344
+ counter. add ( - 3 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1342
1345
1343
1346
test_context. flush_metrics ( ) ;
1344
1347
@@ -1367,19 +1370,19 @@ mod tests {
1367
1370
1368
1371
let data_point1 = find_datapoint_with_key_value ( & sum. data_points , "key1" , "value2" )
1369
1372
. expect ( "datapoint with key1=value2 expected" ) ;
1370
- assert_eq ! ( data_point1. value, 3 ) ;
1373
+ assert_eq ! ( data_point1. value, 7 ) ;
1371
1374
1372
1375
// Reset and report more measurements
1373
1376
test_context. reset_metrics ( ) ;
1374
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1375
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1376
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1377
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1377
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1378
+ counter. add ( - 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1379
+ counter. add ( - 5 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1380
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1378
1381
counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1379
1382
1380
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1381
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1382
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1383
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1384
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1385
+ counter. add ( - 3 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1383
1386
1384
1387
test_context. flush_metrics ( ) ;
1385
1388
@@ -1396,9 +1399,9 @@ mod tests {
1396
1399
let data_point1 = find_datapoint_with_key_value ( & sum. data_points , "key1" , "value2" )
1397
1400
. expect ( "datapoint with key1=value2 expected" ) ;
1398
1401
if temporality == Temporality :: Cumulative {
1399
- assert_eq ! ( data_point1. value, 6 ) ;
1402
+ assert_eq ! ( data_point1. value, 14 ) ;
1400
1403
} else {
1401
- assert_eq ! ( data_point1. value, 3 ) ;
1404
+ assert_eq ! ( data_point1. value, 7 ) ;
1402
1405
}
1403
1406
}
1404
1407
0 commit comments