@@ -217,22 +217,25 @@ mod tests {
217
217
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
218
218
async fn updown_counter_aggregation_cumulative ( ) {
219
219
// Run this test with stdout enabled to see output.
220
- // cargo test counter_aggregation_cumulative --features=metrics,testing -- --nocapture
220
+ // cargo test updown_counter_aggregation_cumulative --features=metrics,testing -- --nocapture
221
221
updown_counter_aggregation_helper ( Temporality :: Cumulative ) ;
222
222
}
223
223
224
224
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
225
225
async fn updown_counter_aggregation_delta ( ) {
226
226
// Run this test with stdout enabled to see output.
227
- // cargo test counter_aggregation_delta --features=metrics,testing -- --nocapture
227
+ // cargo test updown_counter_aggregation_delta --features=metrics,testing -- --nocapture
228
228
updown_counter_aggregation_helper ( Temporality :: Delta ) ;
229
229
}
230
230
231
231
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
232
232
async fn gauge_aggregation ( ) {
233
233
// Run this test with stdout enabled to see output.
234
234
// cargo test gauge_aggregation --features=metrics,testing -- --nocapture
235
- gauge_aggregation_helper ( ) ;
235
+
236
+ // Gauge should use last value aggregation regardless of the aggregation temporality used.
237
+ gauge_aggregation_helper ( Temporality :: Delta ) ;
238
+ gauge_aggregation_helper ( Temporality :: Cumulative ) ;
236
239
}
237
240
238
241
#[ tokio:: test( flavor = "multi_thread" , worker_threads = 1 ) ]
@@ -1134,9 +1137,9 @@ mod tests {
1134
1137
}
1135
1138
}
1136
1139
1137
- fn gauge_aggregation_helper ( ) {
1140
+ fn gauge_aggregation_helper ( temporality : Temporality ) {
1138
1141
// Arrange
1139
- let mut test_context = TestContext :: new ( Temporality :: Delta ) ;
1142
+ let mut test_context = TestContext :: new ( temporality ) ;
1140
1143
let gauge = test_context. meter ( ) . i64_gauge ( "my_gauge" ) . init ( ) ;
1141
1144
1142
1145
// Act
@@ -1274,15 +1277,15 @@ mod tests {
1274
1277
let counter = test_context. i64_up_down_counter ( "test" , "my_updown_counter" , None ) ;
1275
1278
1276
1279
// Act
1277
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1278
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1279
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1280
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1280
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1281
+ counter. add ( - 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1282
+ counter. add ( - 5 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1283
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1281
1284
counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1282
1285
1283
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1284
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1285
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1286
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1287
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1288
+ counter. add ( - 3 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1286
1289
1287
1290
test_context. flush_metrics ( ) ;
1288
1291
@@ -1311,19 +1314,19 @@ mod tests {
1311
1314
1312
1315
let data_point1 = find_datapoint_with_key_value ( & sum. data_points , "key1" , "value2" )
1313
1316
. expect ( "datapoint with key1=value2 expected" ) ;
1314
- assert_eq ! ( data_point1. value, 3 ) ;
1317
+ assert_eq ! ( data_point1. value, 7 ) ;
1315
1318
1316
1319
// Reset and report more measurements
1317
1320
test_context. reset_metrics ( ) ;
1318
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1319
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1320
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1321
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1321
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1322
+ counter. add ( - 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1323
+ counter. add ( - 5 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1324
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1322
1325
counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value1" ) ] ) ;
1323
1326
1324
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1325
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1326
- counter. add ( 1 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1327
+ counter. add ( 10 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1328
+ counter. add ( 0 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1329
+ counter. add ( - 3 , & [ KeyValue :: new ( "key1" , "value2" ) ] ) ;
1327
1330
1328
1331
test_context. flush_metrics ( ) ;
1329
1332
@@ -1340,9 +1343,9 @@ mod tests {
1340
1343
let data_point1 = find_datapoint_with_key_value ( & sum. data_points , "key1" , "value2" )
1341
1344
. expect ( "datapoint with key1=value2 expected" ) ;
1342
1345
if temporality == Temporality :: Cumulative {
1343
- assert_eq ! ( data_point1. value, 6 ) ;
1346
+ assert_eq ! ( data_point1. value, 14 ) ;
1344
1347
} else {
1345
- assert_eq ! ( data_point1. value, 3 ) ;
1348
+ assert_eq ! ( data_point1. value, 7 ) ;
1346
1349
}
1347
1350
}
1348
1351
0 commit comments