Skip to content

Commit 6b422d5

Browse files
committed
Added test to check that histogram buckets are selected correctly
1 parent e0b962a commit 6b422d5

File tree

1 file changed

+23
-0
lines changed

1 file changed

+23
-0
lines changed

opentelemetry-sdk/src/metrics/internal/histogram.rs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -208,3 +208,26 @@ impl<T: Number> Histogram<T> {
208208
(h.data_points.len(), new_agg.map(|a| Box::new(a) as Box<_>))
209209
}
210210
}
211+
212+
#[cfg(test)]
213+
mod tests {
214+
use super::*;
215+
216+
#[test]
217+
fn check_buckets_are_selected_correctly() {
218+
let hist = Histogram::<i64>::new(vec![1.0, 3.0, 6.0], false, false);
219+
for v in 0..10 {
220+
hist.measure(v, &[]);
221+
}
222+
let (count, dp) = hist.cumulative(None);
223+
let dp = dp.unwrap();
224+
let dp = dp.as_any().downcast_ref::<data::Histogram<i64>>().unwrap();
225+
assert_eq!(count, 1);
226+
assert_eq!(dp.data_points[0].count, 4);
227+
assert_eq!(dp.data_points[0].bucket_counts.len(), 4);
228+
assert_eq!(dp.data_points[0].bucket_counts[0], 1); // 0
229+
assert_eq!(dp.data_points[0].bucket_counts[1], 2); // 1, 2
230+
assert_eq!(dp.data_points[0].bucket_counts[2], 3); // 3, 4, 5
231+
assert_eq!(dp.data_points[0].bucket_counts[3], 4); // 6, 7, 8, 9
232+
}
233+
}

0 commit comments

Comments
 (0)