| 1 |
// This Source Code Form is subject to the terms of the Mozilla Public |
| 2 |
// License, v. 2.0. If a copy of the MPL was not distributed with this |
| 3 |
// file, You can obtain one at https://mozilla.org/MPL/2.0/. |
| 4 |
|
| 5 |
//! This integration test should model how the RLB is used when embedded in another Rust application |
| 6 |
//! (e.g. FOG/Firefox Desktop). |
| 7 |
//! |
| 8 |
//! We write a single test scenario per file to avoid any state keeping across runs |
| 9 |
//! (different files run as different processes). |
| 10 |
|
| 11 |
mod common; |
| 12 |
|
| 13 |
/// Some user metrics. |
| 14 |
mod metrics { |
| 15 |
use glean::private::*; |
| 16 |
use glean::traits; |
| 17 |
use glean::CommonMetricData; |
| 18 |
use once_cell::sync::Lazy; |
| 19 |
use std::collections::HashMap; |
| 20 |
|
| 21 |
pub struct SomeExtras { |
| 22 |
extra1: Option<String>, |
| 23 |
extra2: Option<bool>, |
| 24 |
} |
| 25 |
|
| 26 |
impl traits::ExtraKeys for SomeExtras { |
| 27 |
const ALLOWED_KEYS: &'static [&'static str] = &["extra1", "extra2"]; |
| 28 |
|
| 29 |
fn into_ffi_extra(self) -> HashMap<String, String> { |
| 30 |
let mut map = HashMap::new(); |
| 31 |
|
| 32 |
self.extra1 |
| 33 |
.and_then(|val| map.insert("extra1".to_string(), val)); |
| 34 |
self.extra2 |
| 35 |
.and_then(|val| map.insert("extra2".to_string(), val.to_string())); |
| 36 |
|
| 37 |
map |
| 38 |
} |
| 39 |
} |
| 40 |
|
| 41 |
#[allow(non_upper_case_globals)] |
| 42 |
pub static countit: Lazy<CounterMetric> = Lazy::new(|| { |
| 43 |
CounterMetric::new(CommonMetricData { |
| 44 |
name: "count_von_count".into(), |
| 45 |
category: "sesame".into(), |
| 46 |
send_in_pings: vec!["validation".into()], |
| 47 |
dynamic_label: Some("ah_ah_ah".into()), |
| 48 |
..Default::default() |
| 49 |
}) |
| 50 |
}); |
| 51 |
|
| 52 |
#[allow(non_upper_case_globals)] |
| 53 |
pub static event: Lazy<EventMetric<SomeExtras>> = Lazy::new(|| { |
| 54 |
EventMetric::new(CommonMetricData { |
| 55 |
name: "birthday".into(), |
| 56 |
category: "shire".into(), |
| 57 |
send_in_pings: vec!["validation".into()], |
| 58 |
dynamic_label: Some("111th".into()), |
| 59 |
..Default::default() |
| 60 |
}) |
| 61 |
}); |
| 62 |
|
| 63 |
#[allow(non_upper_case_globals)] |
| 64 |
pub static object: Lazy<ObjectMetric<i32>> = Lazy::new(|| { |
| 65 |
ObjectMetric::new(CommonMetricData { |
| 66 |
name: "objection".into(), |
| 67 |
category: "court".into(), |
| 68 |
send_in_pings: vec!["validation".into()], |
| 69 |
..Default::default() |
| 70 |
}) |
| 71 |
}); |
| 72 |
} |
| 73 |
|
| 74 |
/// Test scenario: We have an unknown metric, and wish to get metadata about the metric. |
| 75 |
/// |
| 76 |
/// The app is initialized, in turn Glean gets initialized without problems. |
| 77 |
/// We retrieve information about the metric. |
| 78 |
/// And later the whole process is shutdown. |
| 79 |
#[test] |
| 80 |
fn check_metadata() { |
| 81 |
use glean::MetricIdentifier; |
| 82 |
common::enable_test_logging(); |
| 83 |
|
| 84 |
// Pick the counter metric to test the blanket implementation of |
| 85 |
// MetricIdentifier for types that implement MetricType |
| 86 |
let (category, name, label) = metrics::countit.get_identifiers(); |
| 87 |
assert_eq!(category, "sesame"); |
| 88 |
assert_eq!(name, "count_von_count"); |
| 89 |
assert_eq!(label, Some("ah_ah_ah")); |
| 90 |
|
| 91 |
// Events and Objects have MetricIdentifier implemented explicitly, as |
| 92 |
// they wrap the glean-core Event and Object types |
| 93 |
let (category, name, label) = metrics::event.get_identifiers(); |
| 94 |
assert_eq!(category, "shire"); |
| 95 |
assert_eq!(name, "birthday"); |
| 96 |
assert_eq!(label, Some("111th")); |
| 97 |
|
| 98 |
let (category, name, label) = metrics::object.get_identifiers(); |
| 99 |
assert_eq!(category, "court"); |
| 100 |
assert_eq!(name, "objection"); |
| 101 |
assert_eq!(label, None); |
| 102 |
|
| 103 |
glean::shutdown(); |
| 104 |
} |