forked from Floorp-Projects/Floorp
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1632131 - Simple smoke test for FOG's string metric type. r=chutten
A first Rust test, which should run without any interaction with Firefox. This will eventually break down when we get IPC in there. Depends on D72128 Differential Revision: https://phabricator.services.mozilla.com/D72385
- Loading branch information
Showing
6 changed files
with
77 additions
and
0 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
// This Source Code Form is subject to the terms of the Mozilla Public | ||
// License, v. 2.0. If a copy of the MPL was not distributed with this | ||
// file, You can obtain one at https://mozilla.org/MPL/2.0/. | ||
|
||
use std::sync::{Mutex, MutexGuard}; | ||
|
||
use glean::once_cell::sync::Lazy; | ||
|
||
const GLOBAL_APPLICATION_ID: &str = "org.mozilla.firefox.test"; | ||
|
||
/// UGLY HACK. | ||
/// We use a global lock to force synchronization of all tests, even if run multi-threaded. | ||
/// This allows us to run without `--test-threads 1`.` | ||
pub fn lock_test() -> MutexGuard<'static, ()> { | ||
static GLOBAL_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(())); | ||
|
||
GLOBAL_LOCK.lock().unwrap() | ||
} | ||
|
||
// Create a new instance of Glean with a temporary directory. | ||
// We need to keep the `TempDir` alive, so that it's not deleted before we stop using it. | ||
pub fn setup_glean(tempdir: Option<tempfile::TempDir>) -> tempfile::TempDir { | ||
let dir = match tempdir { | ||
Some(tempdir) => tempdir, | ||
None => tempfile::tempdir().unwrap(), | ||
}; | ||
let tmpname = dir.path().display().to_string(); | ||
|
||
let cfg = glean_core::Configuration { | ||
data_path: tmpname, | ||
application_id: GLOBAL_APPLICATION_ID.into(), | ||
upload_enabled: true, | ||
max_events: None, | ||
delay_ping_lifetime_io: false, | ||
}; | ||
let glean = glean_core::Glean::new(cfg).unwrap(); | ||
glean_core::setup_glean(glean).expect("can't set up global Glean object"); | ||
|
||
dir | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
mod common; | ||
use common::*; | ||
|
||
use glean::metrics::{CommonMetricData, Lifetime, StringMetric}; | ||
|
||
#[test] | ||
fn sets_string_value() { | ||
let _lock = lock_test(); | ||
let _t = setup_glean(None); | ||
let store_names: Vec<String> = vec!["store1".into()]; | ||
|
||
let metric = StringMetric::new(CommonMetricData { | ||
name: "string_metric".into(), | ||
category: "telemetry".into(), | ||
send_in_pings: store_names.clone(), | ||
disabled: false, | ||
lifetime: Lifetime::Ping, | ||
..Default::default() | ||
}); | ||
|
||
metric.set("test_string_value"); | ||
|
||
assert_eq!( | ||
"test_string_value", | ||
metric.test_get_value("store1").unwrap() | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters