| 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::{Lifetime, TimeUnit}; |
| 17 |
use glean_core::CommonMetricData; |
| 18 |
use once_cell::sync::Lazy; |
| 19 |
|
| 20 |
#[allow(non_upper_case_globals)] |
| 21 |
pub static initialization: Lazy<TimespanMetric> = Lazy::new(|| { |
| 22 |
TimespanMetric::new( |
| 23 |
CommonMetricData { |
| 24 |
name: "initialization".into(), |
| 25 |
category: "sample".into(), |
| 26 |
send_in_pings: vec!["validation".into()], |
| 27 |
lifetime: Lifetime::Ping, |
| 28 |
disabled: false, |
| 29 |
..Default::default() |
| 30 |
}, |
| 31 |
TimeUnit::Nanosecond, |
| 32 |
) |
| 33 |
}); |
| 34 |
} |
| 35 |
|
| 36 |
mod pings { |
| 37 |
use super::*; |
| 38 |
use glean::private::PingType; |
| 39 |
use once_cell::sync::Lazy; |
| 40 |
|
| 41 |
#[allow(non_upper_case_globals)] |
| 42 |
pub static validation: Lazy<PingType> = Lazy::new(|| { |
| 43 |
common::PingBuilder::new("validation") |
| 44 |
.with_send_if_empty(true) |
| 45 |
.build() |
| 46 |
}); |
| 47 |
} |
| 48 |
|
| 49 |
/// Test scenario: Glean is never initialized. |
| 50 |
/// |
| 51 |
/// Glean is never initialized. |
| 52 |
/// Some data is recorded early on. |
| 53 |
/// And later the whole process is shutdown. |
| 54 |
#[test] |
| 55 |
fn never_initialize() { |
| 56 |
common::enable_test_logging(); |
| 57 |
|
| 58 |
metrics::initialization.start(); |
| 59 |
|
| 60 |
// NOT calling `initialize` here. |
| 61 |
// In apps this might happen for several reasons: |
| 62 |
// 1. Process doesn't run long enough for Glean to be initialized. |
| 63 |
// 2. Getting some early data used for initialize fails |
| 64 |
|
| 65 |
pings::validation.submit(None); |
| 66 |
|
| 67 |
// We can't test for data either, as that would panic because init was never called. |
| 68 |
|
| 69 |
glean::shutdown(); |
| 70 |
} |