Skip to content

Commit 7dc9799

Browse files
committed
fix: make test config public
1 parent 911f5de commit 7dc9799

2 files changed

Lines changed: 29 additions & 29 deletions

File tree

dogstatsd/src/aggregator.rs

Lines changed: 28 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
//! The aggregation of metrics.
22
3+
use std::sync::Mutex;
34
use crate::constants;
45
use crate::datadog::{self, Metric as MetricToShip, Series};
56
use crate::errors;
@@ -357,6 +358,33 @@ fn tags_string_to_vector(tags: Option<Ustr>) -> Vec<String> {
357358
.collect()
358359
}
359360

361+
#[cfg(test)]
362+
pub fn assert_value(aggregator_mutex: &Mutex<Aggregator>, metric_id: &str, value: f64) {
363+
let aggregator = aggregator_mutex.lock().unwrap();
364+
if let Some(e) = aggregator.get_entry_by_id(metric_id.into(), None) {
365+
let metric = e.metric_value.get_value().unwrap();
366+
assert!((metric - value).abs() < PRECISION);
367+
} else {
368+
panic!("{}", format!("{metric_id} not found"));
369+
}
370+
}
371+
372+
#[cfg(test)]
373+
pub fn assert_sketch(aggregator_mutex: &Mutex<Aggregator>, metric_id: &str, value: f64) {
374+
let aggregator = aggregator_mutex.lock().unwrap();
375+
if let Some(e) = aggregator.get_entry_by_id(metric_id.into(), None) {
376+
let metric = e.metric_value.get_sketch().unwrap();
377+
assert!((metric.max().unwrap() - value).abs() < PRECISION);
378+
assert!((metric.min().unwrap() - value).abs() < PRECISION);
379+
assert!((metric.sum().unwrap() - value).abs() < PRECISION);
380+
assert!((metric.avg().unwrap() - value).abs() < PRECISION);
381+
} else {
382+
panic!("{}", format!("{metric_id} not found"));
383+
}
384+
}
385+
#[cfg(test)]
386+
const PRECISION: f64 = 0.000_000_01;
387+
360388
#[cfg(test)]
361389
#[allow(clippy::unwrap_used)]
362390
pub mod tests {
@@ -366,9 +394,6 @@ pub mod tests {
366394
use datadog_protos::metrics::SketchPayload;
367395
use hashbrown::hash_table;
368396
use protobuf::Message;
369-
use std::sync::Mutex;
370-
371-
const PRECISION: f64 = 0.000_000_01;
372397

373398
const SINGLE_METRIC_SIZE: usize = 187;
374399
const SINGLE_DISTRIBUTION_SIZE: u64 = 135;
@@ -378,29 +403,6 @@ pub mod tests {
378403
"_dd.compute_stats:1",
379404
];
380405

381-
pub fn assert_value(aggregator_mutex: &Mutex<Aggregator>, metric_id: &str, value: f64) {
382-
let aggregator = aggregator_mutex.lock().unwrap();
383-
if let Some(e) = aggregator.get_entry_by_id(metric_id.into(), None) {
384-
let metric = e.metric_value.get_value().unwrap();
385-
assert!((metric - value).abs() < PRECISION);
386-
} else {
387-
panic!("{}", format!("{metric_id} not found"));
388-
}
389-
}
390-
391-
pub fn assert_sketch(aggregator_mutex: &Mutex<Aggregator>, metric_id: &str, value: f64) {
392-
let aggregator = aggregator_mutex.lock().unwrap();
393-
if let Some(e) = aggregator.get_entry_by_id(metric_id.into(), None) {
394-
let metric = e.metric_value.get_sketch().unwrap();
395-
assert!((metric.max().unwrap() - value).abs() < PRECISION);
396-
assert!((metric.min().unwrap() - value).abs() < PRECISION);
397-
assert!((metric.sum().unwrap() - value).abs() < PRECISION);
398-
assert!((metric.avg().unwrap() - value).abs() < PRECISION);
399-
} else {
400-
panic!("{}", format!("{metric_id} not found"));
401-
}
402-
}
403-
404406
#[test]
405407
fn insertion() {
406408
let mut aggregator = Aggregator::new(Vec::new(), 2).unwrap();

dogstatsd/src/dogstatsd.rs

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -104,9 +104,7 @@ impl DogStatsD {
104104
#[cfg(test)]
105105
#[allow(clippy::unwrap_used)]
106106
mod tests {
107-
use crate::aggregator::tests::assert_sketch;
108-
use crate::aggregator::tests::assert_value;
109-
use crate::aggregator::Aggregator;
107+
use crate::aggregator::{assert_sketch, assert_value, Aggregator};
110108
use crate::dogstatsd::{BufferReader, DogStatsD};
111109
use std::net::{IpAddr, Ipv4Addr, SocketAddr};
112110
use std::sync::{Arc, Mutex};

0 commit comments

Comments
 (0)