Debian Codegraph @

third_party/rust/glean/tests/init_fails.rs

raw
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 std::{thread, time::Duration};
14
15 use glean::ConfigurationBuilder;
16
17 /// Some user metrics.
18 mod metrics {
19 use glean::private::*;
20 use glean::{Lifetime, TimeUnit};
21 use glean_core::CommonMetricData;
22 use once_cell::sync::Lazy;
23
24 #[allow(non_upper_case_globals)]
25 pub static initialization: Lazy<TimespanMetric> = Lazy::new(|| {
26 TimespanMetric::new(
27 CommonMetricData {
28 name: "initialization".into(),
29 category: "sample".into(),
30 send_in_pings: vec!["validation".into()],
31 lifetime: Lifetime::Ping,
32 disabled: false,
33 ..Default::default()
34 },
35 TimeUnit::Nanosecond,
36 )
37 });
38 }
39
40 mod pings {
41 use super::*;
42 use glean::private::PingType;
43 use once_cell::sync::Lazy;
44
45 #[allow(non_upper_case_globals)]
46 pub static validation: Lazy<PingType> = Lazy::new(|| {
47 common::PingBuilder::new("validation")
48 .with_send_if_empty(true)
49 .build()
50 });
51 }
52
53 /// Test scenario: Glean initialization fails.
54 ///
55 /// App tries to initialize Glean, but that somehow fails.
56 #[test]
57 fn init_fails() {
58 common::enable_test_logging();
59
60 metrics::initialization.start();
61
62 // Create a custom configuration to use a validating uploader.
63 let dir = tempfile::tempdir().unwrap();
64 let tmpname = dir.path().to_path_buf();
65
66 _ = &*pings::validation;
67 let cfg = ConfigurationBuilder::new(true, tmpname, "")
68 .with_server_endpoint("invalid-test-host")
69 .build();
70 common::initialize(cfg);
71
72 metrics::initialization.stop();
73
74 pings::validation.submit(None);
75
76 // We don't test for data here, as that would block on the dispatcher.
77
78 // Give it a short amount of time to actually finish initialization.
79 thread::sleep(Duration::from_millis(500));
80
81 glean::shutdown();
82 }