Skip to content

Commit

Permalink
RLB: Convert tests to use ConfigurationBuilder
Browse files Browse the repository at this point in the history
  • Loading branch information
badboy committed Dec 15, 2022
1 parent 9f25fbc commit 2bd31b2
Show file tree
Hide file tree
Showing 11 changed files with 42 additions and 119 deletions.
12 changes: 3 additions & 9 deletions glean-core/rlb/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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![]);
Expand Down
17 changes: 5 additions & 12 deletions glean-core/rlb/examples/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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(),
Expand Down
16 changes: 4 additions & 12 deletions glean-core/rlb/src/common_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down
4 changes: 2 additions & 2 deletions glean-core/rlb/src/configuration.rs
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,7 @@ pub struct Builder {
/// Default: `None`
pub uploader: Option<Box<dyn PingUploader + 'static>>,
/// 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
Expand All @@ -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,
}
}
Expand Down
14 changes: 2 additions & 12 deletions glean-core/rlb/src/lib.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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!());
Expand Down
16 changes: 4 additions & 12 deletions glean-core/rlb/tests/init_fails.rs
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mod common;

use std::{thread, time::Duration};

use glean::Configuration;
use glean::ConfigurationBuilder;

/// Some user metrics.
mod metrics {
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 4 additions & 12 deletions glean-core/rlb/tests/no_time_to_init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mod common;

use glean::Configuration;
use glean::ConfigurationBuilder;

/// Some user metrics.
mod metrics {
Expand Down Expand Up @@ -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();
Expand Down
16 changes: 4 additions & 12 deletions glean-core/rlb/tests/overflowing_preinit.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mod common;

use glean::Configuration;
use glean::ConfigurationBuilder;

/// Some user metrics.
mod metrics {
Expand Down Expand Up @@ -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 {
Expand Down
17 changes: 5 additions & 12 deletions glean-core/rlb/tests/persist_ping_lifetime.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mod common;

use glean::{ClientInfoMetrics, Configuration};
use glean::{ClientInfoMetrics, Configuration, ConfigurationBuilder};
use std::path::PathBuf;

/// Some user metrics.
Expand All @@ -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?
Expand Down
17 changes: 5 additions & 12 deletions glean-core/rlb/tests/persist_ping_lifetime_nopanic.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
16 changes: 4 additions & 12 deletions glean-core/rlb/tests/simple.rs
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
mod common;

use glean::Configuration;
use glean::ConfigurationBuilder;

/// Some user metrics.
mod metrics {
Expand Down Expand Up @@ -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();
Expand Down

0 comments on commit 2bd31b2

Please sign in to comment.