From 2bd31b26a5afa1986f679d885619c412ff139b57 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Thu, 15 Dec 2022 13:54:04 +0100 Subject: [PATCH] RLB: Convert tests to use ConfigurationBuilder --- glean-core/rlb/README.md | 12 +++--------- glean-core/rlb/examples/prototype.rs | 17 +++++------------ glean-core/rlb/src/common_test.rs | 16 ++++------------ glean-core/rlb/src/configuration.rs | 4 ++-- glean-core/rlb/src/lib.rs | 14 ++------------ glean-core/rlb/tests/init_fails.rs | 16 ++++------------ glean-core/rlb/tests/no_time_to_init.rs | 16 ++++------------ glean-core/rlb/tests/overflowing_preinit.rs | 16 ++++------------ glean-core/rlb/tests/persist_ping_lifetime.rs | 17 +++++------------ .../rlb/tests/persist_ping_lifetime_nopanic.rs | 17 +++++------------ glean-core/rlb/tests/simple.rs | 16 ++++------------ 11 files changed, 42 insertions(+), 119 deletions(-) diff --git a/glean-core/rlb/README.md b/glean-core/rlb/README.md index d99b0e3563..4ec6bba914 100644 --- a/glean-core/rlb/README.md +++ b/glean-core/rlb/README.md @@ -19,15 +19,9 @@ All documentation is available online: ## Example ```rust,no_run -use glean::{Configuration, Error, metrics::*}; - -let cfg = Configuration { - data_path: "/tmp/data".into(), - application_id: "org.mozilla.glean_core.example".into(), - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: false, -}; +use glean::{ConfigurationBuilder, Error, metrics::*}; + +let cfg = ConfigurationBuilder::new(true, "/tmp/data", "org.mozilla.glean_core.example").build(); glean::initialize(cfg)?; let prototype_ping = PingType::new("prototype", true, true, vec![]); diff --git a/glean-core/rlb/examples/prototype.rs b/glean-core/rlb/examples/prototype.rs index 7b74721872..630638cc59 100644 --- a/glean-core/rlb/examples/prototype.rs +++ b/glean-core/rlb/examples/prototype.rs @@ -8,7 +8,7 @@ use std::path::PathBuf; use once_cell::sync::Lazy; use tempfile::Builder; -use glean::{private::PingType, ClientInfoMetrics, Configuration}; +use glean::{private::PingType, ClientInfoMetrics, ConfigurationBuilder}; pub mod glean_metrics { use glean::{private::BooleanMetric, CommonMetricData, Lifetime}; @@ -43,17 +43,10 @@ fn main() { root.path().to_path_buf() }; - let cfg = Configuration { - data_path, - application_id: "org.mozilla.glean_core.example".into(), - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: false, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: true, - trim_data_to_registered_pings: false, - }; + let cfg = ConfigurationBuilder::new(true, data_path, "org.mozilla.glean_core.example") + .with_server_endpoint("invalid-test-host") + .with_use_core_mps(true) + .build(); let client_info = ClientInfoMetrics { app_build: env!("CARGO_PKG_VERSION").to_string(), diff --git a/glean-core/rlb/src/common_test.rs b/glean-core/rlb/src/common_test.rs index 4876eba42e..fdb7cfadbf 100644 --- a/glean-core/rlb/src/common_test.rs +++ b/glean-core/rlb/src/common_test.rs @@ -3,7 +3,7 @@ // file, You can obtain one at https://mozilla.org/MPL/2.0/. use crate::ClientInfoMetrics; -use crate::Configuration; +use crate::{Configuration, ConfigurationBuilder}; use std::sync::{Mutex, MutexGuard}; use once_cell::sync::Lazy; @@ -40,17 +40,9 @@ pub(crate) fn new_glean( let cfg = match configuration { Some(c) => c, - None => Configuration { - data_path: tmpname, - application_id: GLOBAL_APPLICATION_ID.into(), - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: false, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: false, - trim_data_to_registered_pings: false, - }, + None => ConfigurationBuilder::new(true, tmpname, GLOBAL_APPLICATION_ID) + .with_server_endpoint("invalid-test-host") + .build(), }; crate::test_reset_glean(cfg, ClientInfoMetrics::unknown(), clear_stores); diff --git a/glean-core/rlb/src/configuration.rs b/glean-core/rlb/src/configuration.rs index 75e5ecc813..4a18d1acdc 100644 --- a/glean-core/rlb/src/configuration.rs +++ b/glean-core/rlb/src/configuration.rs @@ -61,7 +61,7 @@ pub struct Builder { /// Default: `None` pub uploader: Option>, /// Optional: Whether Glean should schedule "metrics" pings for you. - /// Default: `true` + /// Default: `false` pub use_core_mps: bool, /// Optional: Whether Glean should limit its storage to only that of registered pings. /// Unless you know that all your and your libraries' pings are appropriately registered @@ -85,7 +85,7 @@ impl Builder { delay_ping_lifetime_io: false, server_endpoint: None, uploader: None, - use_core_mps: true, + use_core_mps: false, trim_data_to_registered_pings: false, } } diff --git a/glean-core/rlb/src/lib.rs b/glean-core/rlb/src/lib.rs index 8d8fa6634d..5f7ebe97cb 100644 --- a/glean-core/rlb/src/lib.rs +++ b/glean-core/rlb/src/lib.rs @@ -18,18 +18,8 @@ //! Initialize Glean, register a ping and then send it. //! //! ```rust,no_run -//! # use glean::{Configuration, ClientInfoMetrics, Error, private::*}; -//! let cfg = Configuration { -//! data_path: "/tmp/data".into(), -//! application_id: "org.mozilla.glean_core.example".into(), -//! upload_enabled: true, -//! max_events: None, -//! delay_ping_lifetime_io: false, -//! server_endpoint: None, -//! uploader: None, -//! use_core_mps: false, -//! trim_data_to_registered_pings: false, -//! }; +//! # use glean::{ConfigurationBuilder, ClientInfoMetrics, Error, private::*}; +//! let cfg = ConfigurationBuilder::new(true, "/tmp/data", "org.mozilla.glean_core.example").build(); //! glean::initialize(cfg, ClientInfoMetrics::unknown()); //! //! let prototype_ping = PingType::new("prototype", true, true, vec!()); diff --git a/glean-core/rlb/tests/init_fails.rs b/glean-core/rlb/tests/init_fails.rs index fde1fab1d8..2269da89ff 100644 --- a/glean-core/rlb/tests/init_fails.rs +++ b/glean-core/rlb/tests/init_fails.rs @@ -12,7 +12,7 @@ mod common; use std::{thread, time::Duration}; -use glean::Configuration; +use glean::ConfigurationBuilder; /// Some user metrics. mod metrics { @@ -59,17 +59,9 @@ fn init_fails() { let dir = tempfile::tempdir().unwrap(); let tmpname = dir.path().to_path_buf(); - let cfg = Configuration { - data_path: tmpname, - application_id: "".into(), // An empty application ID is invalid. - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: false, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: false, - trim_data_to_registered_pings: false, - }; + let cfg = ConfigurationBuilder::new(true, tmpname, "") + .with_server_endpoint("invalid-test-host") + .build(); common::initialize(cfg); metrics::initialization.stop(); diff --git a/glean-core/rlb/tests/no_time_to_init.rs b/glean-core/rlb/tests/no_time_to_init.rs index d5c08834ad..7d51e514d6 100644 --- a/glean-core/rlb/tests/no_time_to_init.rs +++ b/glean-core/rlb/tests/no_time_to_init.rs @@ -10,7 +10,7 @@ mod common; -use glean::Configuration; +use glean::ConfigurationBuilder; /// Some user metrics. mod metrics { @@ -57,17 +57,9 @@ fn init_fails() { let dir = tempfile::tempdir().unwrap(); let tmpname = dir.path().to_path_buf(); - let cfg = Configuration { - data_path: tmpname, - application_id: "firefox-desktop".into(), // An empty application ID is invalid. - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: false, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: false, - trim_data_to_registered_pings: false, - }; + let cfg = ConfigurationBuilder::new(true, tmpname, "firefox-desktop") + .with_server_endpoint("invalid-test-host") + .build(); common::initialize(cfg); metrics::initialization.stop(); diff --git a/glean-core/rlb/tests/overflowing_preinit.rs b/glean-core/rlb/tests/overflowing_preinit.rs index df07e6ea54..6d4ec7f6ae 100644 --- a/glean-core/rlb/tests/overflowing_preinit.rs +++ b/glean-core/rlb/tests/overflowing_preinit.rs @@ -10,7 +10,7 @@ mod common; -use glean::Configuration; +use glean::ConfigurationBuilder; /// Some user metrics. mod metrics { @@ -62,17 +62,9 @@ fn overflowing_the_task_queue_records_telemetry() { let dir = tempfile::tempdir().unwrap(); let tmpname = dir.path().to_path_buf(); - let cfg = Configuration { - data_path: tmpname, - application_id: "firefox-desktop".into(), - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: false, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: false, - trim_data_to_registered_pings: false, - }; + let cfg = ConfigurationBuilder::new(true, tmpname, "firefox-desktop") + .with_server_endpoint("invalid-test-host") + .build(); // Insert a bunch of tasks to overflow the queue. for _ in 0..1010 { diff --git a/glean-core/rlb/tests/persist_ping_lifetime.rs b/glean-core/rlb/tests/persist_ping_lifetime.rs index dcadeebb6a..f73673f46f 100644 --- a/glean-core/rlb/tests/persist_ping_lifetime.rs +++ b/glean-core/rlb/tests/persist_ping_lifetime.rs @@ -10,7 +10,7 @@ mod common; -use glean::{ClientInfoMetrics, Configuration}; +use glean::{ClientInfoMetrics, Configuration, ConfigurationBuilder}; use std::path::PathBuf; /// Some user metrics. @@ -34,17 +34,10 @@ mod metrics { } fn cfg_new(tmpname: PathBuf) -> Configuration { - Configuration { - data_path: tmpname, - application_id: "firefox-desktop".into(), - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: true, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: false, - trim_data_to_registered_pings: false, - } + ConfigurationBuilder::new(true, tmpname, "firefox-desktop") + .with_server_endpoint("invalid-test-host") + .with_delay_ping_lifetime_io(true) + .build() } /// Test scenario: Are ping-lifetime data persisted on shutdown when delayed? diff --git a/glean-core/rlb/tests/persist_ping_lifetime_nopanic.rs b/glean-core/rlb/tests/persist_ping_lifetime_nopanic.rs index a05e1442ee..18d54e9033 100644 --- a/glean-core/rlb/tests/persist_ping_lifetime_nopanic.rs +++ b/glean-core/rlb/tests/persist_ping_lifetime_nopanic.rs @@ -10,21 +10,14 @@ mod common; -use glean::Configuration; +use glean::{Configuration, ConfigurationBuilder}; use std::path::PathBuf; fn cfg_new(tmpname: PathBuf) -> Configuration { - Configuration { - data_path: tmpname, - application_id: "firefox-desktop".into(), - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: true, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: false, - trim_data_to_registered_pings: false, - } + ConfigurationBuilder::new(true, tmpname, "firefox-desktop") + .with_server_endpoint("invalid-test-host") + .with_delay_ping_lifetime_io(true) + .build() } /// Test scenario: `persist_ping_lifetime_data` called after shutdown. diff --git a/glean-core/rlb/tests/simple.rs b/glean-core/rlb/tests/simple.rs index ef5ad88a28..efc8d9a0f8 100644 --- a/glean-core/rlb/tests/simple.rs +++ b/glean-core/rlb/tests/simple.rs @@ -10,7 +10,7 @@ mod common; -use glean::Configuration; +use glean::ConfigurationBuilder; /// Some user metrics. mod metrics { @@ -59,17 +59,9 @@ fn simple_lifecycle() { let dir = tempfile::tempdir().unwrap(); let tmpname = dir.path().to_path_buf(); - let cfg = Configuration { - data_path: tmpname, - application_id: "firefox-desktop".into(), - upload_enabled: true, - max_events: None, - delay_ping_lifetime_io: false, - server_endpoint: Some("invalid-test-host".into()), - uploader: None, - use_core_mps: false, - trim_data_to_registered_pings: false, - }; + let cfg = ConfigurationBuilder::new(true, tmpname, "firefox-desktop") + .with_server_endpoint("invalid-test-host") + .build(); common::initialize(cfg); metrics::initialization.stop();