Skip to content

Commit a1e2f3a

Browse files
refactor: parametrize tests
1 parent df412fe commit a1e2f3a

File tree

2 files changed

+27
-81
lines changed

2 files changed

+27
-81
lines changed

Cargo.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@ opentelemetry-proto = { path = "opentelemetry-proto", version= "0.31", default-f
7474
opentelemetry-semantic-conventions = { path = "opentelemetry-semantic-conventions", version = "0.31", default-features = false }
7575
opentelemetry-stdout = { path = "opentelemetry-stdout", version = "0.31", default-features = false }
7676
percent-encoding = "2.0"
77-
rstest = "0.23.0"
77+
rstest = "0.26.1"
7878
schemars = "0.8"
7979
sysinfo = "0.32"
8080
tempfile = "3.3.0"

opentelemetry-sdk/src/metrics/mod.rs

Lines changed: 26 additions & 80 deletions
Original file line numberDiff line numberDiff line change
@@ -129,6 +129,8 @@ mod tests {
129129
use std::thread;
130130
use std::time::Duration;
131131

132+
use rstest::rstest;
133+
132134
// Run all tests in this mod
133135
// cargo test metrics::tests --features=testing,spec_unstable_metrics_views
134136
// Note for all tests from this point onwards in this mod:
@@ -377,34 +379,15 @@ mod tests {
377379
counter_aggregation_overflow_helper_custom_limit(Temporality::Cumulative);
378380
}
379381

380-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
381-
async fn counter_aggregation_attribute_order_sorted_first_delta() {
382-
// Run this test with stdout enabled to see output.
383-
// cargo test counter_aggregation_attribute_order_sorted_first_delta --features=testing -- --nocapture
384-
counter_aggregation_attribute_order_helper(Temporality::Delta, true);
385-
}
386-
387-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
388-
async fn counter_aggregation_attribute_order_sorted_first_cumulative() {
389-
// Run this test with stdout enabled to see output.
390-
// cargo test counter_aggregation_attribute_order_sorted_first_cumulative --features=testing -- --nocapture
391-
counter_aggregation_attribute_order_helper(Temporality::Cumulative, true);
392-
}
393-
394-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
395-
async fn counter_aggregation_attribute_order_unsorted_first_delta() {
382+
#[rstest]
383+
#[case(Temporality::Delta, true)]
384+
#[case(Temporality::Delta, false)]
385+
#[case(Temporality::Cumulative, true)]
386+
#[case(Temporality::Cumulative, false)]
387+
fn counter_aggregation(#[case] temporality: Temporality, #[case] start_sorted: bool) {
396388
// Run this test with stdout enabled to see output.
397-
// cargo test counter_aggregation_attribute_order_unsorted_first_delta --features=testing -- --nocapture
398-
399-
counter_aggregation_attribute_order_helper(Temporality::Delta, false);
400-
}
401-
402-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
403-
async fn counter_aggregation_attribute_order_unsorted_first_cumulative() {
404-
// Run this test with stdout enabled to see output.
405-
// cargo test counter_aggregation_attribute_order_unsorted_first_cumulative --features=testing -- --nocapture
406-
407-
counter_aggregation_attribute_order_helper(Temporality::Cumulative, false);
389+
// cargo test counter_aggregation_attribute --features=testing -- --nocapture
390+
counter_aggregation_attribute_order_helper(temporality, start_sorted);
408391
}
409392

410393
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
@@ -473,60 +456,23 @@ mod tests {
473456
observable_gauge_aggregation_helper(Temporality::Cumulative, true);
474457
}
475458

476-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
477-
async fn observable_counter_aggregation_cumulative_non_zero_increment() {
478-
// Run this test with stdout enabled to see output.
479-
// cargo test observable_counter_aggregation_cumulative_non_zero_increment --features=testing -- --nocapture
480-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 10, 4, false);
481-
}
482-
483-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
484-
async fn observable_counter_aggregation_cumulative_non_zero_increment_no_attrs() {
485-
// Run this test with stdout enabled to see output.
486-
// cargo test observable_counter_aggregation_cumulative_non_zero_increment_no_attrs --features=testing -- --nocapture
487-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 10, 4, true);
488-
}
489-
490-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
491-
async fn observable_counter_aggregation_delta_non_zero_increment() {
492-
// Run this test with stdout enabled to see output.
493-
// cargo test observable_counter_aggregation_delta_non_zero_increment --features=testing -- --nocapture
494-
observable_counter_aggregation_helper(Temporality::Delta, 100, 10, 4, false);
495-
}
496-
497-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
498-
async fn observable_counter_aggregation_delta_non_zero_increment_no_attrs() {
499-
// Run this test with stdout enabled to see output.
500-
// cargo test observable_counter_aggregation_delta_non_zero_increment_no_attrs --features=testing -- --nocapture
501-
observable_counter_aggregation_helper(Temporality::Delta, 100, 10, 4, true);
502-
}
503-
504-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
505-
async fn observable_counter_aggregation_cumulative_zero_increment() {
506-
// Run this test with stdout enabled to see output.
507-
// cargo test observable_counter_aggregation_cumulative_zero_increment --features=testing -- --nocapture
508-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 0, 4, false);
509-
}
510-
511-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
512-
async fn observable_counter_aggregation_cumulative_zero_increment_no_attrs() {
513-
// Run this test with stdout enabled to see output.
514-
// cargo test observable_counter_aggregation_cumulative_zero_increment_no_attrs --features=testing -- --nocapture
515-
observable_counter_aggregation_helper(Temporality::Cumulative, 100, 0, 4, true);
516-
}
517-
518-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
519-
async fn observable_counter_aggregation_delta_zero_increment() {
520-
// Run this test with stdout enabled to see output.
521-
// cargo test observable_counter_aggregation_delta_zero_increment --features=testing -- --nocapture
522-
observable_counter_aggregation_helper(Temporality::Delta, 100, 0, 4, false);
523-
}
524-
525-
#[tokio::test(flavor = "multi_thread", worker_threads = 1)]
526-
async fn observable_counter_aggregation_delta_zero_increment_no_attrs() {
459+
#[rstest]
460+
#[case(Temporality::Cumulative, 10, false)]
461+
#[case(Temporality::Cumulative, 10, true)]
462+
#[case(Temporality::Delta, 10, false)]
463+
#[case(Temporality::Delta, 10, true)]
464+
#[case(Temporality::Cumulative, 0, false)]
465+
#[case(Temporality::Cumulative, 0, true)]
466+
#[case(Temporality::Delta, 0, false)]
467+
#[case(Temporality::Delta, 0, true)]
468+
fn observable_counter_aggregation(
469+
#[case] temporality: Temporality,
470+
#[case] increment: u64,
471+
#[case] is_empty_attributes: bool,
472+
) {
527473
// Run this test with stdout enabled to see output.
528-
// cargo test observable_counter_aggregation_delta_zero_increment_no_attrs --features=testing -- --nocapture
529-
observable_counter_aggregation_helper(Temporality::Delta, 100, 0, 4, true);
474+
// cargo test observable_counter_aggregation --features=testing -- --nocapture
475+
observable_counter_aggregation_helper(temporality, 100, increment, 4, is_empty_attributes);
530476
}
531477

532478
fn observable_counter_aggregation_helper(

0 commit comments

Comments
 (0)