Debian Codegraph @

third_party/rust/glean/tests/overflowing_preinit.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 glean::ConfigurationBuilder;
14
15 /// Some user metrics.
16 mod metrics {
17 use glean::private::*;
18 use glean::Lifetime;
19 use glean_core::CommonMetricData;
20 use once_cell::sync::Lazy;
21
22 #[allow(non_upper_case_globals)]
23 pub static rapid_counting: Lazy<CounterMetric> = Lazy::new(|| {
24 CounterMetric::new(CommonMetricData {
25 name: "rapid_counting".into(),
26 category: "sample".into(),
27 send_in_pings: vec!["metrics".into()],
28 lifetime: Lifetime::Ping,
29 disabled: false,
30 ..Default::default()
31 })
32 });
33
34 // This is a hack, but a good one:
35 //
36 // To avoid reaching into RLB internals we re-create the metric so we can look at it.
37 #[allow(non_upper_case_globals)]
38 pub static preinit_tasks_overflow: Lazy<CounterMetric> = Lazy::new(|| {
39 CounterMetric::new(CommonMetricData {
40 category: "glean.error".into(),
41 name: "preinit_tasks_overflow".into(),
42 send_in_pings: vec!["metrics".into()],
43 lifetime: Lifetime::Ping,
44 disabled: false,
45 ..Default::default()
46 })
47 });
48 }
49
50 /// Test scenario: Lots of metric recordings before init.
51 ///
52 /// The app starts recording metrics before Glean is initialized.
53 /// Once initialized the recordings are processed and data is persisted.
54 /// The pre-init dispatcher queue records how many recordings over the limit it saw.
55 ///
56 /// This is an integration test to avoid dealing with resetting the dispatcher.
57 #[ignore] // oops, long running test see Bug 1911350 for more info
58 #[test]
59 fn overflowing_the_task_queue_records_telemetry() {
60 common::enable_test_logging();
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 let cfg = ConfigurationBuilder::new(true, tmpname, "firefox-desktop")
67 .with_server_endpoint("invalid-test-host")
68 .build();
69
70 // Insert a bunch of tasks to overflow the queue.
71 for _ in 0..1000010 {
72 metrics::rapid_counting.add(1);
73 }
74
75 // Now initialize Glean
76 common::initialize(cfg);
77
78 assert_eq!(Some(1000000), metrics::rapid_counting.test_get_value(None));
79
80 // The metrics counts the total number of overflowing tasks,
81 // (and the count of tasks in the queue when we overflowed: bug 1764573)
82 // this might include Glean-internal tasks.
83 let val = metrics::preinit_tasks_overflow
84 .test_get_value(None)
85 .unwrap();
86 assert!(val >= 10);
87
88 glean::shutdown();
89 }