mod common;
use glean::{ClientInfoMetrics, Configuration};
use std::path::PathBuf;
mod metrics {
use glean::private::*;
use glean::Lifetime;
use glean_core::CommonMetricData;
use once_cell::sync::Lazy;
#[allow(non_upper_case_globals)]
pub static boo: Lazy<BooleanMetric> = Lazy::new(|| {
BooleanMetric::new(CommonMetricData {
name: "boo".into(),
category: "sample".into(),
send_in_pings: vec!["validation".into()],
lifetime: Lifetime::Ping,
disabled: false,
..Default::default()
})
});
}
fn cfg_new(tmpname: PathBuf) -> Configuration {
Configuration {
data_path: tmpname,
application_id: "firefox-desktop".into(),
upload_enabled: true,
max_events: None,
delay_ping_lifetime_io: true,
server_endpoint: Some("invalid-test-host".into()),
uploader: None,
use_core_mps: false,
}
}
#[test]
fn delayed_ping_data() {
common::enable_test_logging();
metrics::boo.set(true);
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().to_path_buf();
common::initialize(cfg_new(tmpname.clone()));
assert!(
metrics::boo.test_get_value(None).unwrap(),
"Data should be present. Doesn't mean it's persisted, though."
);
glean::test_reset_glean(
cfg_new(tmpname.clone()),
ClientInfoMetrics::unknown(),
false,
);
assert_eq!(
None,
metrics::boo.test_get_value(None),
"Data should not have made it to disk on unclean shutdown."
);
metrics::boo.set(true);
glean::shutdown();
glean::test_reset_glean(cfg_new(tmpname), ClientInfoMetrics::unknown(), false);
assert!(
metrics::boo.test_get_value(None).unwrap(),
"Data must be persisted between clean shutdown and init!"
);
glean::shutdown(); }