diff options
author | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
---|---|---|
committer | Daniel Baumann <daniel.baumann@progress-linux.org> | 2024-04-19 01:14:29 +0000 |
commit | fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8 (patch) | |
tree | 4c1ccaf5486d4f2009f9a338a98a83e886e29c97 /third_party/rust/glean-core/tests | |
parent | Releasing progress-linux version 124.0.1-1~progress7.99u1. (diff) | |
download | firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.tar.xz firefox-fbaf0bb26397aa498eb9156f06d5a6fe34dd7dd8.zip |
Merging upstream version 125.0.1.
Signed-off-by: Daniel Baumann <daniel.baumann@progress-linux.org>
Diffstat (limited to 'third_party/rust/glean-core/tests')
-rw-r--r-- | third_party/rust/glean-core/tests/custom_distribution.rs | 20 | ||||
-rw-r--r-- | third_party/rust/glean-core/tests/event.rs | 2 | ||||
-rw-r--r-- | third_party/rust/glean-core/tests/object.rs | 104 | ||||
-rw-r--r-- | third_party/rust/glean-core/tests/ping.rs | 14 | ||||
-rw-r--r-- | third_party/rust/glean-core/tests/ping_maker.rs | 26 | ||||
-rw-r--r-- | third_party/rust/glean-core/tests/timing_distribution.rs | 6 |
6 files changed, 139 insertions, 33 deletions
diff --git a/third_party/rust/glean-core/tests/custom_distribution.rs b/third_party/rust/glean-core/tests/custom_distribution.rs index 43c69fb26d..4cdfa5e99b 100644 --- a/third_party/rust/glean-core/tests/custom_distribution.rs +++ b/third_party/rust/glean-core/tests/custom_distribution.rs @@ -40,7 +40,7 @@ mod linear { HistogramType::Linear, ); - metric.accumulate_samples_sync(&glean, vec![50]); + metric.accumulate_samples_sync(&glean, &[50]); let snapshot = metric .get_value(&glean, "store1") @@ -84,7 +84,7 @@ mod linear { HistogramType::Linear, ); - metric.accumulate_samples_sync(&glean, vec![50]); + metric.accumulate_samples_sync(&glean, &[50]); for store_name in store_names { let snapshot = StorageManager @@ -126,7 +126,7 @@ mod linear { // Accumulate the samples. We intentionally do not report // negative values to not trigger error reporting. - metric.accumulate_samples_sync(&glean, [1, 2, 3].to_vec()); + metric.accumulate_samples_sync(&glean, &[1, 2, 3]); let snapshot = metric .get_value(&glean, "store1") @@ -168,7 +168,7 @@ mod linear { ); // Accumulate the samples. - metric.accumulate_samples_sync(&glean, [-1, 1, 2, 3].to_vec()); + metric.accumulate_samples_sync(&glean, &[-1, 1, 2, 3]); let snapshot = metric .get_value(&glean, "store1") @@ -209,7 +209,7 @@ mod linear { HistogramType::Linear, ); - metric.accumulate_samples_sync(&glean, vec![50]); + metric.accumulate_samples_sync(&glean, &[50]); let snapshot = metric.get_value(&glean, "store1"); assert!(snapshot.is_some()); @@ -242,7 +242,7 @@ mod exponential { HistogramType::Exponential, ); - metric.accumulate_samples_sync(&glean, vec![50]); + metric.accumulate_samples_sync(&glean, &[50]); let snapshot = metric .get_value(&glean, "store1") @@ -286,7 +286,7 @@ mod exponential { HistogramType::Exponential, ); - metric.accumulate_samples_sync(&glean, vec![50]); + metric.accumulate_samples_sync(&glean, &[50]); for store_name in store_names { let snapshot = StorageManager @@ -328,7 +328,7 @@ mod exponential { // Accumulate the samples. We intentionally do not report // negative values to not trigger error reporting. - metric.accumulate_samples_sync(&glean, [1, 2, 3].to_vec()); + metric.accumulate_samples_sync(&glean, &[1, 2, 3]); let snapshot = metric .get_value(&glean, "store1") @@ -370,7 +370,7 @@ mod exponential { ); // Accumulate the samples. - metric.accumulate_samples_sync(&glean, [-1, 1, 2, 3].to_vec()); + metric.accumulate_samples_sync(&glean, &[-1, 1, 2, 3]); let snapshot = metric .get_value(&glean, "store1") @@ -411,7 +411,7 @@ mod exponential { HistogramType::Exponential, ); - metric.accumulate_samples_sync(&glean, vec![50]); + metric.accumulate_samples_sync(&glean, &[50]); let snapshot = metric.get_value(&glean, "store1"); assert!(snapshot.is_some()); diff --git a/third_party/rust/glean-core/tests/event.rs b/third_party/rust/glean-core/tests/event.rs index ed8f7d807f..c83e225ca2 100644 --- a/third_party/rust/glean-core/tests/event.rs +++ b/third_party/rust/glean-core/tests/event.rs @@ -166,6 +166,7 @@ fn test_sending_of_event_ping_when_it_fills_up() { true, false, true, + true, vec!["max_capacity".to_string()], )); } @@ -450,6 +451,7 @@ fn event_storage_trimming() { true, false, true, + true, vec![], )); diff --git a/third_party/rust/glean-core/tests/object.rs b/third_party/rust/glean-core/tests/object.rs new file mode 100644 index 0000000000..1e734e99d2 --- /dev/null +++ b/third_party/rust/glean-core/tests/object.rs @@ -0,0 +1,104 @@ +// 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/. + +mod common; +use crate::common::*; + +use serde_json::json; + +use glean_core::metrics::*; +use glean_core::storage::StorageManager; +use glean_core::{CommonMetricData, Lifetime}; + +#[test] +fn object_serializer_should_correctly_serialize_objects() { + let (mut tempdir, _) = tempdir(); + + { + // 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 metric = ObjectMetric::new(CommonMetricData { + name: "object_metric".into(), + category: "telemetry".into(), + send_in_pings: vec!["store1".into()], + disabled: false, + lifetime: Lifetime::User, + ..Default::default() + }); + + let obj = serde_json::from_str("{ \"value\": 1 }").unwrap(); + metric.set_sync(&glean, obj); + + let snapshot = StorageManager + .snapshot_as_json(glean.storage(), "store1", true) + .unwrap(); + assert_eq!( + json!({"object": {"telemetry.object_metric": { "value": 1 }}}), + snapshot + ); + } + + // 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(); + assert_eq!( + json!({"object": {"telemetry.object_metric": { "value": 1 }}}), + snapshot + ); + } +} + +#[test] +fn set_value_properly_sets_the_value_in_all_stores() { + let (glean, _t) = new_glean(None); + let store_names: Vec<String> = vec!["store1".into(), "store2".into()]; + + let metric = ObjectMetric::new(CommonMetricData { + name: "object_metric".into(), + category: "telemetry".into(), + send_in_pings: store_names.clone(), + disabled: false, + lifetime: Lifetime::Ping, + ..Default::default() + }); + + let obj = serde_json::from_str("{ \"value\": 1 }").unwrap(); + metric.set_sync(&glean, obj); + + for store_name in store_names { + let snapshot = StorageManager + .snapshot_as_json(glean.storage(), &store_name, true) + .unwrap(); + + assert_eq!( + json!({"object": {"telemetry.object_metric": { "value": 1 }}}), + snapshot + ); + } +} + +#[test] +fn getting_data_json_encoded() { + let (glean, _t) = new_glean(None); + + let object: ObjectMetric = ObjectMetric::new(CommonMetricData { + name: "transformation".into(), + category: "local".into(), + send_in_pings: vec!["store1".into()], + ..Default::default() + }); + + let obj_str = "{\"value\":1}"; + let obj = serde_json::from_str(obj_str).unwrap(); + object.set_sync(&glean, obj); + + assert_eq!(obj_str, object.get_value(&glean, Some("store1")).unwrap()); +} diff --git a/third_party/rust/glean-core/tests/ping.rs b/third_party/rust/glean-core/tests/ping.rs index 0ee3736168..17944b4c24 100644 --- a/third_party/rust/glean-core/tests/ping.rs +++ b/third_party/rust/glean-core/tests/ping.rs @@ -15,7 +15,7 @@ use glean_core::Lifetime; fn write_ping_to_disk() { let (mut glean, _temp) = new_glean(None); - let ping = PingType::new("metrics", true, false, true, vec![]); + let ping = PingType::new("metrics", true, false, true, true, vec![]); glean.register_ping_type(&ping); // We need to store a metric as an empty ping is not stored. @@ -36,7 +36,7 @@ fn write_ping_to_disk() { fn disabling_upload_clears_pending_pings() { let (mut glean, _t) = new_glean(None); - let ping = PingType::new("metrics", true, false, true, vec![]); + let ping = PingType::new("metrics", true, false, true, true, vec![]); glean.register_ping_type(&ping); // We need to store a metric as an empty ping is not stored. @@ -105,9 +105,9 @@ fn deletion_request_only_when_toggled_from_on_to_off() { fn empty_pings_with_flag_are_sent() { let (mut glean, _t) = new_glean(None); - let ping1 = PingType::new("custom-ping1", true, true, true, vec![]); + let ping1 = PingType::new("custom-ping1", true, true, true, true, vec![]); glean.register_ping_type(&ping1); - let ping2 = PingType::new("custom-ping2", true, false, true, vec![]); + let ping2 = PingType::new("custom-ping2", true, false, true, true, vec![]); glean.register_ping_type(&ping2); // No data is stored in either of the custom pings @@ -139,10 +139,10 @@ fn test_pings_submitted_metric() { None, ); - let metrics_ping = PingType::new("metrics", true, false, true, vec![]); + let metrics_ping = PingType::new("metrics", true, false, true, true, vec![]); glean.register_ping_type(&metrics_ping); - let baseline_ping = PingType::new("baseline", true, false, true, vec![]); + let baseline_ping = PingType::new("baseline", true, false, true, true, vec![]); glean.register_ping_type(&baseline_ping); // We need to store a metric as an empty ping is not stored. @@ -218,7 +218,7 @@ fn test_pings_submitted_metric() { fn events_ping_with_metric_but_no_events_is_not_sent() { let (mut glean, _t) = new_glean(None); - let events_ping = PingType::new("events", true, true, true, vec![]); + let events_ping = PingType::new("events", true, true, true, true, vec![]); glean.register_ping_type(&events_ping); let counter = CounterMetric::new(CommonMetricData { name: "counter".into(), diff --git a/third_party/rust/glean-core/tests/ping_maker.rs b/third_party/rust/glean-core/tests/ping_maker.rs index 29b6bccaca..bc3aac6311 100644 --- a/third_party/rust/glean-core/tests/ping_maker.rs +++ b/third_party/rust/glean-core/tests/ping_maker.rs @@ -13,7 +13,7 @@ fn set_up_basic_ping() -> (Glean, PingMaker, PingType, tempfile::TempDir) { let (tempdir, _) = tempdir(); let (mut glean, t) = new_glean(Some(tempdir)); let ping_maker = PingMaker::new(); - let ping_type = PingType::new("store1", true, false, true, vec![]); + let ping_type = PingType::new("store1", true, false, true, true, vec![]); glean.register_ping_type(&ping_type); // Record something, so the ping will have data @@ -89,12 +89,12 @@ fn test_metrics_must_report_experimentation_id() { trim_data_to_registered_pings: false, log_level: None, rate_limit: None, - enable_event_timestamps: false, + enable_event_timestamps: true, experimentation_id: Some("test-experimentation-id".to_string()), }) .unwrap(); let ping_maker = PingMaker::new(); - let ping_type = PingType::new("store1", true, false, true, vec![]); + let ping_type = PingType::new("store1", true, false, true, true, vec![]); glean.register_ping_type(&ping_type); // Record something, so the ping will have data @@ -141,13 +141,13 @@ fn experimentation_id_is_removed_if_send_if_empty_is_false() { trim_data_to_registered_pings: false, log_level: None, rate_limit: None, - enable_event_timestamps: false, + enable_event_timestamps: true, experimentation_id: Some("test-experimentation-id".to_string()), }) .unwrap(); let ping_maker = PingMaker::new(); - let unknown_ping_type = PingType::new("unknown", true, false, true, vec![]); + let unknown_ping_type = PingType::new("unknown", true, false, true, true, vec![]); glean.register_ping_type(&unknown_ping_type); assert!(ping_maker @@ -163,7 +163,7 @@ fn collect_must_report_none_when_no_data_is_stored() { let (mut glean, ping_maker, ping_type, _t) = set_up_basic_ping(); - let unknown_ping_type = PingType::new("unknown", true, false, true, vec![]); + let unknown_ping_type = PingType::new("unknown", true, false, true, true, vec![]); glean.register_ping_type(&ping_type); assert!(ping_maker @@ -187,7 +187,7 @@ fn seq_number_must_be_sequential() { for i in 0..=1 { for ping_name in ["store1", "store2"].iter() { - let ping_type = PingType::new(*ping_name, true, false, true, vec![]); + let ping_type = PingType::new(*ping_name, true, false, true, true, vec![]); let ping = ping_maker .collect(&glean, &ping_type, None, "", "") .unwrap(); @@ -200,7 +200,7 @@ fn seq_number_must_be_sequential() { // Test that ping sequence numbers increase independently. { - let ping_type = PingType::new("store1", true, false, true, vec![]); + let ping_type = PingType::new("store1", true, false, true, true, vec![]); // 3rd ping of store1 let ping = ping_maker @@ -218,7 +218,7 @@ fn seq_number_must_be_sequential() { } { - let ping_type = PingType::new("store2", true, false, true, vec![]); + let ping_type = PingType::new("store2", true, false, true, true, vec![]); // 3rd ping of store2 let ping = ping_maker @@ -229,7 +229,7 @@ fn seq_number_must_be_sequential() { } { - let ping_type = PingType::new("store1", true, false, true, vec![]); + let ping_type = PingType::new("store1", true, false, true, true, vec![]); // 5th ping of store1 let ping = ping_maker @@ -244,7 +244,7 @@ fn seq_number_must_be_sequential() { fn clear_pending_pings() { let (mut glean, _t) = new_glean(None); let ping_maker = PingMaker::new(); - let ping_type = PingType::new("store1", true, false, true, vec![]); + let ping_type = PingType::new("store1", true, false, true, true, vec![]); glean.register_ping_type(&ping_type); // Record something, so the ping will have data @@ -272,7 +272,7 @@ fn no_pings_submitted_if_upload_disabled() { // Regression test, bug 1603571 let (mut glean, _t) = new_glean(None); - let ping_type = PingType::new("store1", true, true, true, vec![]); + let ping_type = PingType::new("store1", true, true, true, true, vec![]); glean.register_ping_type(&ping_type); assert!(ping_type.submit_sync(&glean, None)); @@ -290,7 +290,7 @@ fn no_pings_submitted_if_upload_disabled() { fn metadata_is_correctly_added_when_necessary() { let (mut glean, _t) = new_glean(None); glean.set_debug_view_tag("valid-tag"); - let ping_type = PingType::new("store1", true, true, true, vec![]); + let ping_type = PingType::new("store1", true, true, true, true, vec![]); glean.register_ping_type(&ping_type); assert!(ping_type.submit_sync(&glean, None)); diff --git a/third_party/rust/glean-core/tests/timing_distribution.rs b/third_party/rust/glean-core/tests/timing_distribution.rs index 96f7fae5af..59ce5fbadb 100644 --- a/third_party/rust/glean-core/tests/timing_distribution.rs +++ b/third_party/rust/glean-core/tests/timing_distribution.rs @@ -169,7 +169,7 @@ fn the_accumulate_samples_api_correctly_stores_timing_values() { // Accumulate the samples. We intentionally do not report // negative values to not trigger error reporting. - metric.accumulate_samples_sync(&glean, [1, 2, 3].to_vec()); + metric.accumulate_samples_sync(&glean, &[1, 2, 3]); let snapshot = metric .get_value(&glean, "store1") @@ -211,7 +211,7 @@ fn the_accumulate_samples_api_correctly_handles_negative_values() { ); // Accumulate the samples. - metric.accumulate_samples_sync(&glean, [-1, 1, 2, 3].to_vec()); + metric.accumulate_samples_sync(&glean, &[-1, 1, 2, 3]); let snapshot = metric .get_value(&glean, "store1") @@ -255,7 +255,7 @@ fn the_accumulate_samples_api_correctly_handles_overflowing_values() { const MAX_SAMPLE_TIME: u64 = 1000 * 1000 * 1000 * 60 * 10; let overflowing_val = MAX_SAMPLE_TIME as i64 + 1; // Accumulate the samples. - metric.accumulate_samples_sync(&glean, [overflowing_val, 1, 2, 3].to_vec()); + metric.accumulate_samples_sync(&glean, &[overflowing_val, 1, 2, 3]); let snapshot = metric .get_value(&glean, "store1") |