// 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::time::Duration;
mod common; usecrate::common::*;
use serde_json::json;
use glean_core::metrics::*; use glean_core::storage::StorageManager; use glean_core::{test_get_num_recorded_errors, ErrorType}; use glean_core::{CommonMetricData, Lifetime};
// Tests ported from glean-ac
#[test] fn serializer_should_correctly_serialize_timespans() { let (mut tempdir, _) = tempdir();
let duration = 60;
{ // We give tempdir to the `new_glean` function... let (glean, dir) = new_glean(Some(tempdir)); // And then we get it back once that function returns.
tempdir = dir;
let val = metric
.get_value(&glean, "store1")
.expect("Value should be stored");
assert_eq!(duration, val, "Recorded timespan should be positive.");
}
// Make a new Glean instance here, which should force reloading of the data from disk // so we can ensure it persisted, because it has User lifetime
{ let (glean, _t) = new_glean(Some(tempdir)); let snapshot = StorageManager
.snapshot_as_json(glean.storage(), "store1", true)
.unwrap();
let duration = 60;
metric.set_start(&glean, 0);
metric.set_stop(&glean, duration);
// No error should be recorded here: we had no prior value stored.
assert!(test_get_num_recorded_errors(&glean, metric.meta(), ErrorType::InvalidState).is_err());
let first_value = metric.get_value(&glean, "store1").unwrap();
assert_eq!(duration, first_value);
let second_value = metric.get_value(&glean, "store1").unwrap();
assert_eq!(second_value, first_value);
// Make sure that the error has been recorded: we had a stored value, the // new measurement was dropped.
assert_eq!(
Ok(1),
test_get_num_recorded_errors(&glean, metric.meta(), ErrorType::InvalidState)
);
}
#[test] fn recorded_time_conforms_to_resolution() { let (glean, _t) = new_glean(None);
// Timer is started.
metric.set_start(&glean, 0); // User disables telemetry upload.
glean.set_upload_enabled(false); // App code eventually stops the timer. // We should clear internal state as upload is disabled.
metric.set_stop(&glean, 40);
// App code eventually starts the timer again.
metric.set_start(&glean, 100); // User enables telemetry upload again.
glean.set_upload_enabled(true); // App code eventually stops the timer. // The full timespan is recorded.
metric.set_stop(&glean, 200);
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.