Skip to content

Commit 3f39ec3

Browse files
committed
Update tests
1 parent 78943fd commit 3f39ec3

File tree

1 file changed

+25
-22
lines changed
  • opentelemetry-sdk/src/metrics

1 file changed

+25
-22
lines changed

opentelemetry-sdk/src/metrics/mod.rs

+25-22
Original file line numberDiff line numberDiff line change
@@ -217,22 +217,25 @@ mod tests {
217217
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
218218
async fn updown_counter_aggregation_cumulative() {
219219
// 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
221221
updown_counter_aggregation_helper(Temporality::Cumulative);
222222
}
223223

224224
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
225225
async fn updown_counter_aggregation_delta() {
226226
// 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
228228
updown_counter_aggregation_helper(Temporality::Delta);
229229
}
230230

231231
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
232232
async fn gauge_aggregation() {
233233
// Run this test with stdout enabled to see output.
234234
// 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);
236239
}
237240

238241
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -1134,9 +1137,9 @@ mod tests {
11341137
}
11351138
}
11361139

1137-
fn gauge_aggregation_helper() {
1140+
fn gauge_aggregation_helper(temporality: Temporality) {
11381141
// Arrange
1139-
let mut test_context = TestContext::new(Temporality::Delta);
1142+
let mut test_context = TestContext::new(temporality);
11401143
let gauge = test_context.meter().i64_gauge("my_gauge").init();
11411144

11421145
// Act
@@ -1274,15 +1277,15 @@ mod tests {
12741277
let counter = test_context.i64_up_down_counter("test", "my_updown_counter", None);
12751278

12761279
// 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")]);
12811284
counter.add(1, &[KeyValue::new("key1", "value1")]);
12821285

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")]);
12861289

12871290
test_context.flush_metrics();
12881291

@@ -1311,19 +1314,19 @@ mod tests {
13111314

13121315
let data_point1 = find_datapoint_with_key_value(&sum.data_points, "key1", "value2")
13131316
.expect("datapoint with key1=value2 expected");
1314-
assert_eq!(data_point1.value, 3);
1317+
assert_eq!(data_point1.value, 7);
13151318

13161319
// Reset and report more measurements
13171320
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")]);
13221325
counter.add(1, &[KeyValue::new("key1", "value1")]);
13231326

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")]);
13271330

13281331
test_context.flush_metrics();
13291332

@@ -1340,9 +1343,9 @@ mod tests {
13401343
let data_point1 = find_datapoint_with_key_value(&sum.data_points, "key1", "value2")
13411344
.expect("datapoint with key1=value2 expected");
13421345
if temporality == Temporality::Cumulative {
1343-
assert_eq!(data_point1.value, 6);
1346+
assert_eq!(data_point1.value, 14);
13441347
} else {
1345-
assert_eq!(data_point1.value, 3);
1348+
assert_eq!(data_point1.value, 7);
13461349
}
13471350
}
13481351

0 commit comments

Comments
 (0)