mod common;
use glean::{ConfigurationBuilder, ErrorType, TestGetValue};
mod metrics {
use glean::private::*;
use glean::{Lifetime, TimeUnit};
use glean_core::CommonMetricData;
use once_cell::sync::Lazy;
#[allow(non_upper_case_globals)]
pub static boo: Lazy<TimingDistributionMetric> = Lazy::new(|| {
TimingDistributionMetric::new(
CommonMetricData {
name: "boo".into(),
category: "sample".into(),
send_in_pings: vec!["store1".into()],
lifetime: Lifetime::Ping,
disabled: false,
..Default::default()
},
TimeUnit::Millisecond,
)
});
}
#[test]
fn buffered_timing_distribution_works() {
common::enable_test_logging();
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().to_path_buf();
let cfg = ConfigurationBuilder::new(true, tmpname, "firefox-desktop")
.with_server_endpoint("invalid-test-host")
.build();
common::initialize(cfg);
let mut buffer = metrics::boo.start_buffer();
for _ in 0..3 {
buffer.accumulate(10);
}
assert_eq!(None, metrics::boo.test_get_value(None));
drop(buffer);
let data = metrics::boo.test_get_value(None).unwrap();
assert_eq!(3, data.count);
assert_eq!(30 * 1_000_000, data.sum);
let mut buffer = metrics::boo.start_buffer();
for _ in 0..3 {
buffer.accumulate(10);
}
buffer.abandon();
let data = metrics::boo.test_get_value(None).unwrap();
assert_eq!(3, data.count);
assert_eq!(30 * 1_000_000, data.sum);
let mut buffer = metrics::boo.start_buffer();
let large_sample = (1000 * 1000 * 1000 * 60 * 10) + 1;
for _ in 0..10 {
buffer.accumulate(large_sample);
}
drop(buffer);
let data = metrics::boo.test_get_value(None).unwrap();
assert_eq!(13, data.count);
assert_eq!(
10,
metrics::boo.test_get_num_recorded_errors(ErrorType::InvalidValue)
);
glean::shutdown(); }