| 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 |
use glean::{ConfigurationBuilder, ErrorType}; |
| 14 |
use std::time::Duration; |
| 15 |
|
| 16 |
/// A timing_distribution |
| 17 |
mod metrics { |
| 18 |
use glean::private::*; |
| 19 |
use glean::{Lifetime, TimeUnit}; |
| 20 |
use glean_core::CommonMetricData; |
| 21 |
use once_cell::sync::Lazy; |
| 22 |
|
| 23 |
#[allow(non_upper_case_globals)] |
| 24 |
pub static boo: Lazy<TimingDistributionMetric> = Lazy::new(|| { |
| 25 |
TimingDistributionMetric::new( |
| 26 |
CommonMetricData { |
| 27 |
name: "boo".into(), |
| 28 |
category: "sample".into(), |
| 29 |
send_in_pings: vec!["store1".into()], |
| 30 |
lifetime: Lifetime::Ping, |
| 31 |
disabled: false, |
| 32 |
..Default::default() |
| 33 |
}, |
| 34 |
TimeUnit::Millisecond, |
| 35 |
) |
| 36 |
}); |
| 37 |
} |
| 38 |
|
| 39 |
/// Test scenario: Ensure single-sample accumulation works. |
| 40 |
#[test] |
| 41 |
fn raw_duration_works() { |
| 42 |
common::enable_test_logging(); |
| 43 |
|
| 44 |
let dir = tempfile::tempdir().unwrap(); |
| 45 |
let tmpname = dir.path().to_path_buf(); |
| 46 |
|
| 47 |
let cfg = ConfigurationBuilder::new(true, tmpname, "firefox-desktop") |
| 48 |
.with_server_endpoint("invalid-test-host") |
| 49 |
.build(); |
| 50 |
common::initialize(cfg); |
| 51 |
|
| 52 |
metrics::boo.accumulate_raw_duration(Duration::from_secs(1)); |
| 53 |
|
| 54 |
assert_eq!( |
| 55 |
1, |
| 56 |
metrics::boo.test_get_value(None).unwrap().count, |
| 57 |
"Single sample: single count" |
| 58 |
); |
| 59 |
|
| 60 |
// Let's check overflow. |
| 61 |
metrics::boo.accumulate_raw_duration(Duration::from_nanos(u64::MAX)); |
| 62 |
|
| 63 |
assert_eq!(2, metrics::boo.test_get_value(None).unwrap().count); |
| 64 |
assert_eq!( |
| 65 |
1, |
| 66 |
metrics::boo.test_get_num_recorded_errors(ErrorType::InvalidOverflow) |
| 67 |
); |
| 68 |
|
| 69 |
glean::shutdown(); // Cleanly shut down at the end of the test. |
| 70 |
} |