Skip to content

Commit f7b0dd9

Browse files
refactor: parametrize tests (#3256)
Co-authored-by: Scott Gerring <scottgerring@users.noreply.github.com>
1 parent 6e1fbbe commit f7b0dd9

2 files changed

Lines changed: 27 additions & 81 deletions

File tree

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ opentelemetry-proto = { path = "opentelemetry-proto", version = "0.32", default-
7171
opentelemetry-semantic-conventions = { path = "opentelemetry-semantic-conventions", version = "0.32", default-features = false }
7272
opentelemetry-stdout = { path = "opentelemetry-stdout", version = "0.32", default-features = false }
7373
percent-encoding = "2.0"
74-
rstest = "0.23.0"
74+
rstest = "0.26.1"
7575
schemars = "1.0"
7676
sysinfo = "0.32"
7777
tempfile = "3.3.0"

opentelemetry-sdk/src/metrics/mod.rs

Lines changed: 26 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,8 @@ mod tests {
143143
use std::thread;
144144
use std::time::Duration;
145145

146+
use rstest::rstest;
147+
146148
// Run all tests in this mod
147149
// cargo test metrics::tests --features=testing,spec_unstable_metrics_views
148150
// Note for all tests from this point onwards in this mod:
@@ -391,34 +393,15 @@ mod tests {
391393
counter_aggregation_overflow_helper_custom_limit(Temporality::Cumulative);
392394
}
393395

394-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
395-
async fn counter_aggregation_attribute_order_sorted_first_delta() {
396-
// Run this test with stdout enabled to see output.
397-
// cargo test counter_aggregation_attribute_order_sorted_first_delta --features=testing -- --nocapture
398-
counter_aggregation_attribute_order_helper(Temporality::Delta, true);
399-
}
400-
401-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
402-
async fn counter_aggregation_attribute_order_sorted_first_cumulative() {
403-
// Run this test with stdout enabled to see output.
404-
// cargo test counter_aggregation_attribute_order_sorted_first_cumulative --features=testing -- --nocapture
405-
counter_aggregation_attribute_order_helper(Temporality::Cumulative, true);
406-
}
407-
408-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
409-
async fn counter_aggregation_attribute_order_unsorted_first_delta() {
396+
#[rstest]
397+
#[case(Temporality::Delta, true)]
398+
#[case(Temporality::Delta, false)]
399+
#[case(Temporality::Cumulative, true)]
400+
#[case(Temporality::Cumulative, false)]
401+
fn counter_aggregation(#[case] temporality: Temporality, #[case] start_sorted: bool) {
410402
// Run this test with stdout enabled to see output.
411-
// cargo test counter_aggregation_attribute_order_unsorted_first_delta --features=testing -- --nocapture
412-
413-
counter_aggregation_attribute_order_helper(Temporality::Delta, false);
414-
}
415-
416-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
417-
async fn counter_aggregation_attribute_order_unsorted_first_cumulative() {
418-
// Run this test with stdout enabled to see output.
419-
// cargo test counter_aggregation_attribute_order_unsorted_first_cumulative --features=testing -- --nocapture
420-
421-
counter_aggregation_attribute_order_helper(Temporality::Cumulative, false);
403+
// cargo test counter_aggregation_attribute --features=testing -- --nocapture
404+
counter_aggregation_attribute_order_helper(temporality, start_sorted);
422405
}
423406

424407
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -503,60 +486,23 @@ mod tests {
503486
observable_gauge_aggregation_helper(Temporality::Cumulative, true);
504487
}
505488

506-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
507-
async fn observable_counter_aggregation_cumulative_non_zero_increment() {
508-
// Run this test with stdout enabled to see output.
509-
// cargo test observable_counter_aggregation_cumulative_non_zero_increment --features=testing -- --nocapture
510-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 10, 4, false);
511-
}
512-
513-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
514-
async fn observable_counter_aggregation_cumulative_non_zero_increment_no_attrs() {
515-
// Run this test with stdout enabled to see output.
516-
// cargo test observable_counter_aggregation_cumulative_non_zero_increment_no_attrs --features=testing -- --nocapture
517-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 10, 4, true);
518-
}
519-
520-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
521-
async fn observable_counter_aggregation_delta_non_zero_increment() {
522-
// Run this test with stdout enabled to see output.
523-
// cargo test observable_counter_aggregation_delta_non_zero_increment --features=testing -- --nocapture
524-
observable_counter_aggregation_helper(Temporality::Delta, 100, 10, 4, false);
525-
}
526-
527-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
528-
async fn observable_counter_aggregation_delta_non_zero_increment_no_attrs() {
529-
// Run this test with stdout enabled to see output.
530-
// cargo test observable_counter_aggregation_delta_non_zero_increment_no_attrs --features=testing -- --nocapture
531-
observable_counter_aggregation_helper(Temporality::Delta, 100, 10, 4, true);
532-
}
533-
534-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
535-
async fn observable_counter_aggregation_cumulative_zero_increment() {
536-
// Run this test with stdout enabled to see output.
537-
// cargo test observable_counter_aggregation_cumulative_zero_increment --features=testing -- --nocapture
538-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 0, 4, false);
539-
}
540-
541-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
542-
async fn observable_counter_aggregation_cumulative_zero_increment_no_attrs() {
543-
// Run this test with stdout enabled to see output.
544-
// cargo test observable_counter_aggregation_cumulative_zero_increment_no_attrs --features=testing -- --nocapture
545-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 0, 4, true);
546-
}
547-
548-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
549-
async fn observable_counter_aggregation_delta_zero_increment() {
550-
// Run this test with stdout enabled to see output.
551-
// cargo test observable_counter_aggregation_delta_zero_increment --features=testing -- --nocapture
552-
observable_counter_aggregation_helper(Temporality::Delta, 100, 0, 4, false);
553-
}
554-
555-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
556-
async fn observable_counter_aggregation_delta_zero_increment_no_attrs() {
489+
#[rstest]
490+
#[case(Temporality::Cumulative, 10, false)]
491+
#[case(Temporality::Cumulative, 10, true)]
492+
#[case(Temporality::Delta, 10, false)]
493+
#[case(Temporality::Delta, 10, true)]
494+
#[case(Temporality::Cumulative, 0, false)]
495+
#[case(Temporality::Cumulative, 0, true)]
496+
#[case(Temporality::Delta, 0, false)]
497+
#[case(Temporality::Delta, 0, true)]
498+
fn observable_counter_aggregation(
499+
#[case] temporality: Temporality,
500+
#[case] increment: u64,
501+
#[case] is_empty_attributes: bool,
502+
) {
557503
// Run this test with stdout enabled to see output.
558-
// cargo test observable_counter_aggregation_delta_zero_increment_no_attrs --features=testing -- --nocapture
559-
observable_counter_aggregation_helper(Temporality::Delta, 100, 0, 4, true);
504+
// cargo test observable_counter_aggregation --features=testing -- --nocapture
505+
observable_counter_aggregation_helper(temporality, 100, increment, 4, is_empty_attributes);
560506
}
561507

562508
fn observable_counter_aggregation_helper(

0 commit comments

Comments
 (0)