use crate::ClientInfoMetrics;
use crate::{Configuration, ConfigurationBuilder};
use std::sync::{Mutex, MutexGuard};
use once_cell::sync::Lazy;
pub(crate) const GLOBAL_APPLICATION_ID: &str = "org.mozilla.rlb.test";
pub(crate) fn lock_test() -> MutexGuard<'static, ()> {
static GLOBAL_LOCK: Lazy<Mutex<()>> = Lazy::new(|| Mutex::new(()));
env_logger::try_init().ok();
let lock = GLOBAL_LOCK.lock().unwrap();
lock
}
pub(crate) fn new_glean(
configuration: Option<Configuration>,
clear_stores: bool,
) -> tempfile::TempDir {
let dir = tempfile::tempdir().unwrap();
let tmpname = dir.path().to_path_buf();
let cfg = match configuration {
Some(c) => c,
None => ConfigurationBuilder::new(true, tmpname, GLOBAL_APPLICATION_ID)
.with_server_endpoint("invalid-test-host")
.build(),
};
crate::test_reset_glean(cfg, ClientInfoMetrics::unknown(), clear_stores);
dir
}