From 00ce5bdd18b49b987785b3d9b3bf019f6a4a8678 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Thu, 31 Oct 2024 13:38:56 +0100 Subject: [PATCH 1/2] Use the same test ping names consistently throughout all tests This is in preparation of the further changes coming to how we handle pings. --- .../java/mozilla/telemetry/glean/GleanTest.kt | 2 +- glean-core/python/tests/data/core.yaml | 34 +++++++++---------- glean-core/rlb/src/private/event.rs | 6 ++-- glean-core/rlb/src/private/object.rs | 8 ++--- glean-core/rlb/src/test.rs | 2 +- .../rlb/tests/custom_distribution_buffered.rs | 2 +- .../rlb/tests/memory_distribution_buffered.rs | 2 +- .../rlb/tests/timing_distribution_buffered.rs | 2 +- .../timing_distribution_single_sample.rs | 2 +- glean-core/src/event_database/mod.rs | 2 +- glean-core/src/ping/mod.rs | 12 +++---- glean-core/tests/event.rs | 6 ++-- glean-core/tests/rate.rs | 10 +++--- glean-core/tests/storage.rs | 8 ++--- glean-core/tests/string_list.rs | 10 +++--- glean-core/tests/timespan.rs | 4 +-- glean-core/tests/uuid.rs | 6 ++-- 17 files changed, 59 insertions(+), 59 deletions(-) diff --git a/glean-core/android/src/test/java/mozilla/telemetry/glean/GleanTest.kt b/glean-core/android/src/test/java/mozilla/telemetry/glean/GleanTest.kt index 8bc9689154..a787a083e7 100644 --- a/glean-core/android/src/test/java/mozilla/telemetry/glean/GleanTest.kt +++ b/glean-core/android/src/test/java/mozilla/telemetry/glean/GleanTest.kt @@ -535,7 +535,7 @@ class GleanTest { category = "telemetry", lifetime = Lifetime.PING, name = "string_metric", - sendInPings = listOf("default"), + sendInPings = listOf("store1"), ), ) diff --git a/glean-core/python/tests/data/core.yaml b/glean-core/python/tests/data/core.yaml index fe589d74ab..c85895949c 100644 --- a/glean-core/python/tests/data/core.yaml +++ b/glean-core/python/tests/data/core.yaml @@ -20,7 +20,7 @@ telemetry: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 core_ping: @@ -37,7 +37,7 @@ core_ping: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 created: @@ -52,7 +52,7 @@ core_ping: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 sessions: @@ -66,7 +66,7 @@ core_ping: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 durations: @@ -82,7 +82,7 @@ core_ping: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 searches: @@ -105,7 +105,7 @@ core_ping: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 flash_usage: @@ -120,7 +120,7 @@ core_ping: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 default_browser: @@ -134,7 +134,7 @@ core_ping: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 environment: @@ -149,7 +149,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 os: @@ -163,7 +163,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 os_version: @@ -177,7 +177,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 device: @@ -194,7 +194,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 arch: @@ -221,7 +221,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 default_search: @@ -236,7 +236,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 display_version: @@ -251,7 +251,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 distribution_id: @@ -266,7 +266,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 campaign_id: @@ -281,7 +281,7 @@ environment: notification_emails: - CHANGE-ME@example.com send_in_pings: - - core + - store1 expires: 2100-01-01 event_example: diff --git a/glean-core/rlb/src/private/event.rs b/glean-core/rlb/src/private/event.rs index 8b1abca84f..3d9db80351 100644 --- a/glean-core/rlb/src/private/event.rs +++ b/glean-core/rlb/src/private/event.rs @@ -96,7 +96,7 @@ mod test { let metric: EventMetric = EventMetric::new(CommonMetricData { name: "event".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); @@ -133,7 +133,7 @@ mod test { let metric: EventMetric = EventMetric::new(CommonMetricData { name: "event".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); @@ -188,7 +188,7 @@ mod test { CommonMetricData { name: "event".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }, vec!["key1".into(), "key2".into()], diff --git a/glean-core/rlb/src/private/object.rs b/glean-core/rlb/src/private/object.rs index 6e9a684bfd..373145c7d2 100644 --- a/glean-core/rlb/src/private/object.rs +++ b/glean-core/rlb/src/private/object.rs @@ -110,7 +110,7 @@ mod test { let metric: ObjectMetric = ObjectMetric::new(CommonMetricData { name: "object".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); @@ -144,7 +144,7 @@ mod test { let metric: ObjectMetric = ObjectMetric::new(CommonMetricData { name: "object".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); @@ -178,7 +178,7 @@ mod test { let metric: ObjectMetric = ObjectMetric::new(CommonMetricData { name: "object".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); @@ -225,7 +225,7 @@ mod test { let metric: ObjectMetric = ObjectMetric::new(CommonMetricData { name: "object".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); diff --git a/glean-core/rlb/src/test.rs b/glean-core/rlb/src/test.rs index 3cc93151ef..15c57b6ffa 100644 --- a/glean-core/rlb/src/test.rs +++ b/glean-core/rlb/src/test.rs @@ -629,7 +629,7 @@ fn basic_metrics_should_be_cleared_when_disabling_uploading() { let metric = private::StringMetric::new(CommonMetricData { name: "string_metric".into(), category: "telemetry".into(), - send_in_pings: vec!["default".into()], + send_in_pings: vec!["store1".into()], lifetime: Lifetime::Ping, disabled: false, ..Default::default() diff --git a/glean-core/rlb/tests/custom_distribution_buffered.rs b/glean-core/rlb/tests/custom_distribution_buffered.rs index ae92cae5f9..d3995782e2 100644 --- a/glean-core/rlb/tests/custom_distribution_buffered.rs +++ b/glean-core/rlb/tests/custom_distribution_buffered.rs @@ -24,7 +24,7 @@ mod metrics { CommonMetricData { name: "measure".into(), category: "sample".into(), - send_in_pings: vec!["validation".into()], + send_in_pings: vec!["store1".into()], lifetime: Lifetime::Ping, disabled: false, ..Default::default() diff --git a/glean-core/rlb/tests/memory_distribution_buffered.rs b/glean-core/rlb/tests/memory_distribution_buffered.rs index acded0ee4e..973ff60a5f 100644 --- a/glean-core/rlb/tests/memory_distribution_buffered.rs +++ b/glean-core/rlb/tests/memory_distribution_buffered.rs @@ -24,7 +24,7 @@ mod metrics { CommonMetricData { name: "measure".into(), category: "sample".into(), - send_in_pings: vec!["validation".into()], + send_in_pings: vec!["store1".into()], lifetime: Lifetime::Ping, disabled: false, ..Default::default() diff --git a/glean-core/rlb/tests/timing_distribution_buffered.rs b/glean-core/rlb/tests/timing_distribution_buffered.rs index b21cb8377c..4f7b2a2c42 100644 --- a/glean-core/rlb/tests/timing_distribution_buffered.rs +++ b/glean-core/rlb/tests/timing_distribution_buffered.rs @@ -25,7 +25,7 @@ mod metrics { CommonMetricData { name: "boo".into(), category: "sample".into(), - send_in_pings: vec!["validation".into()], + send_in_pings: vec!["store1".into()], lifetime: Lifetime::Ping, disabled: false, ..Default::default() diff --git a/glean-core/rlb/tests/timing_distribution_single_sample.rs b/glean-core/rlb/tests/timing_distribution_single_sample.rs index 1ed296c05d..e6588b3301 100644 --- a/glean-core/rlb/tests/timing_distribution_single_sample.rs +++ b/glean-core/rlb/tests/timing_distribution_single_sample.rs @@ -26,7 +26,7 @@ mod metrics { CommonMetricData { name: "boo".into(), category: "sample".into(), - send_in_pings: vec!["validation".into()], + send_in_pings: vec!["store1".into()], lifetime: Lifetime::Ping, disabled: false, ..Default::default() diff --git a/glean-core/src/event_database/mod.rs b/glean-core/src/event_database/mod.rs index 5b53827d2a..ff0156bcb8 100644 --- a/glean-core/src/event_database/mod.rs +++ b/glean-core/src/event_database/mod.rs @@ -758,7 +758,7 @@ mod test { let (mut glean, dir) = new_glean(None); let db = EventDatabase::new(dir.path()).unwrap(); - let test_storage = "test-storage"; + let test_storage = "store1"; let test_category = "category"; let test_name = "name"; let test_timestamp = 2; diff --git a/glean-core/src/ping/mod.rs b/glean-core/src/ping/mod.rs index f6bea44a1e..27d82f4d45 100644 --- a/glean-core/src/ping/mod.rs +++ b/glean-core/src/ping/mod.rs @@ -426,15 +426,15 @@ mod test { let (mut glean, _t) = new_glean(None); let ping_maker = PingMaker::new(); - assert_eq!(0, ping_maker.get_ping_seq(&glean, "custom")); - assert_eq!(1, ping_maker.get_ping_seq(&glean, "custom")); + assert_eq!(0, ping_maker.get_ping_seq(&glean, "store1")); + assert_eq!(1, ping_maker.get_ping_seq(&glean, "store1")); glean.set_upload_enabled(false); - assert_eq!(0, ping_maker.get_ping_seq(&glean, "custom")); - assert_eq!(0, ping_maker.get_ping_seq(&glean, "custom")); + assert_eq!(0, ping_maker.get_ping_seq(&glean, "store1")); + assert_eq!(0, ping_maker.get_ping_seq(&glean, "store1")); glean.set_upload_enabled(true); - assert_eq!(0, ping_maker.get_ping_seq(&glean, "custom")); - assert_eq!(1, ping_maker.get_ping_seq(&glean, "custom")); + assert_eq!(0, ping_maker.get_ping_seq(&glean, "store1")); + assert_eq!(1, ping_maker.get_ping_seq(&glean, "store1")); } } diff --git a/glean-core/tests/event.rs b/glean-core/tests/event.rs index dcc9668a7f..43a3c9cda1 100644 --- a/glean-core/tests/event.rs +++ b/glean-core/tests/event.rs @@ -396,7 +396,7 @@ fn snapshot_sorts_the_timestamps() { fn ensure_custom_ping_events_dont_overflow() { let (glean, _dir) = new_glean(None); - let store_name = "store-name"; + let store_name = "store1"; let event_meta = CommonMetricData { name: "name".into(), category: "category".into(), @@ -441,7 +441,7 @@ fn ensure_custom_ping_events_dont_overflow() { fn ensure_custom_ping_events_from_multiple_runs_work() { let (mut tempdir, _) = tempdir(); - let store_name = "store-name"; + let store_name = "store1"; let event = EventMetric::new( CommonMetricData { name: "name".into(), @@ -570,7 +570,7 @@ fn with_event_timestamps() { }; let glean = Glean::new(cfg).unwrap(); - let store_name = "store-name"; + let store_name = "store1"; let event = EventMetric::new( CommonMetricData { name: "name".into(), diff --git a/glean-core/tests/rate.rs b/glean-core/tests/rate.rs index f81e10cb53..625afdd506 100644 --- a/glean-core/tests/rate.rs +++ b/glean-core/tests/rate.rs @@ -16,7 +16,7 @@ fn rate_smoke() { let metric: RateMetric = RateMetric::new(CommonMetricData { name: "rate".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); @@ -52,7 +52,7 @@ fn numerator_smoke() { let metric: NumeratorMetric = NumeratorMetric::new(CommonMetricData { name: "rate".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); @@ -89,14 +89,14 @@ fn denominator_smoke() { let meta1 = CommonMetricData { name: "rate1".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }; let meta2 = CommonMetricData { name: "rate2".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }; @@ -105,7 +105,7 @@ fn denominator_smoke() { CommonMetricData { name: "counter".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }, vec![meta1.clone(), meta2.clone()], diff --git a/glean-core/tests/storage.rs b/glean-core/tests/storage.rs index 238fe6855c..ec022cc310 100644 --- a/glean-core/tests/storage.rs +++ b/glean-core/tests/storage.rs @@ -26,14 +26,14 @@ fn can_snapshot() { let local_metric = StringMetric::new(CommonMetricData { name: "can_snapshot_local_metric".into(), category: "local".into(), - send_in_pings: vec!["store".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); local_metric.set_sync(&glean, "snapshot 42"); assert!(StorageManager - .snapshot(glean.storage(), "store", true) + .snapshot(glean.storage(), "store1", true) .is_some()) } @@ -77,7 +77,7 @@ fn storage_is_thread_safe() { let threadsafe_metric = CounterMetric::new(CommonMetricData { name: "threadsafe".into(), category: "global".into(), - send_in_pings: vec!["core".into(), "metrics".into()], + send_in_pings: vec!["store1".into(), "metrics".into()], ..Default::default() }); let threadsafe_metric = Arc::new(threadsafe_metric); @@ -99,7 +99,7 @@ fn storage_is_thread_safe() { child.join().unwrap(); let snapshot = StorageManager - .snapshot_as_json(glean.lock().unwrap().storage(), "core", true) + .snapshot_as_json(glean.lock().unwrap().storage(), "store1", true) .unwrap(); assert_eq!(json!({"counter": { "global.threadsafe": 4 }}), snapshot); } diff --git a/glean-core/tests/string_list.rs b/glean-core/tests/string_list.rs index 7dd5acfbb5..73fe790f97 100644 --- a/glean-core/tests/string_list.rs +++ b/glean-core/tests/string_list.rs @@ -18,25 +18,25 @@ fn list_can_store_multiple_items() { let list: StringListMetric = StringListMetric::new(CommonMetricData { name: "list".into(), category: "local".into(), - send_in_pings: vec!["core".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); list.add_sync(&glean, "first"); - assert_eq!(list.get_value(&glean, "core").unwrap(), vec!["first"]); + assert_eq!(list.get_value(&glean, "store1").unwrap(), vec!["first"]); list.add_sync(&glean, "second"); assert_eq!( - list.get_value(&glean, "core").unwrap(), + list.get_value(&glean, "store1").unwrap(), vec!["first", "second"] ); list.set_sync(&glean, vec!["third".into()]); - assert_eq!(list.get_value(&glean, "core").unwrap(), vec!["third"]); + assert_eq!(list.get_value(&glean, "store1").unwrap(), vec!["third"]); list.add_sync(&glean, "fourth"); assert_eq!( - list.get_value(&glean, "core").unwrap(), + list.get_value(&glean, "store1").unwrap(), vec!["third", "fourth"] ); } diff --git a/glean-core/tests/timespan.rs b/glean-core/tests/timespan.rs index f3cabedfef..9b3a434a8f 100644 --- a/glean-core/tests/timespan.rs +++ b/glean-core/tests/timespan.rs @@ -331,7 +331,7 @@ fn time_cannot_go_backwards() { CommonMetricData { name: "raw_timespan".into(), category: "test".into(), - send_in_pings: vec!["test1".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }, TimeUnit::Millisecond, @@ -340,7 +340,7 @@ fn time_cannot_go_backwards() { // Time cannot go backwards. metric.set_start(&glean, 10); metric.set_stop(&glean, 0); - assert!(metric.get_value(&glean, "test1").is_none()); + assert!(metric.get_value(&glean, "store1").is_none()); assert_eq!( Ok(1), test_get_num_recorded_errors(&glean, metric.meta(), ErrorType::InvalidValue), diff --git a/glean-core/tests/uuid.rs b/glean-core/tests/uuid.rs index c9d5015a72..a1cb23da1a 100644 --- a/glean-core/tests/uuid.rs +++ b/glean-core/tests/uuid.rs @@ -18,19 +18,19 @@ fn uuid_is_generated_and_stored() { let uuid: UuidMetric = UuidMetric::new(CommonMetricData { name: "uuid".into(), category: "local".into(), - send_in_pings: vec!["core".into()], + send_in_pings: vec!["store1".into()], ..Default::default() }); uuid.generate_and_set_sync(&glean); - let snapshot = glean.snapshot("core", false); + let snapshot = glean.snapshot("store1", false); assert!( snapshot.contains(r#""local.uuid": ""#), "Snapshot 1: {snapshot}" ); uuid.generate_and_set_sync(&glean); - let snapshot = glean.snapshot("core", false); + let snapshot = glean.snapshot("store1", false); assert!( snapshot.contains(r#""local.uuid": ""#), "Snapshot 2: {snapshot}" From ef38f09e14dea0dd1303dcf7bd56418e9814d5b2 Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Thu, 31 Oct 2024 13:38:56 +0100 Subject: [PATCH 2/2] In tests register all pings by instantiating them --- .swiftlint.yml | 1 + .../telemetry/glean/testing/GleanTestRule.kt | 33 +++++++++++++++++++ .../telemetry/glean/pings/CustomPingTest.kt | 30 ++++++++--------- glean-core/ios/GleanTests/TestUtils.swift | 31 +++++++++++++++++ glean-core/python/tests/conftest.py | 28 ++++++++++++++++ glean-core/rlb/examples/crashing-threads.rs | 1 + glean-core/rlb/examples/delayed-ping-data.rs | 1 + glean-core/rlb/examples/long-running.rs | 1 + .../rlb/examples/ping-lifetime-flush.rs | 1 + glean-core/rlb/examples/prototype.rs | 1 + glean-core/rlb/src/common_test.rs | 3 ++ glean-core/rlb/tests/common/mod.rs | 3 +- glean-core/rlb/tests/init_fails.rs | 1 + glean-core/rlb/tests/simple.rs | 1 + glean-core/src/lib_unit_tests.rs | 11 ++++++- glean-core/tests/common/mod.rs | 10 ++++-- glean-core/tests/event.rs | 4 ++- 17 files changed, 141 insertions(+), 20 deletions(-) diff --git a/.swiftlint.yml b/.swiftlint.yml index dfd533da6f..7c26d90fc8 100644 --- a/.swiftlint.yml +++ b/.swiftlint.yml @@ -13,6 +13,7 @@ disabled_rules: - force_cast # We'll get to these when we get to them! - todo + - function_body_length identifier_name: # Turn off it complaining about `id` or `let t = title`, etc, but keep diff --git a/glean-core/android/src/main/java/mozilla/telemetry/glean/testing/GleanTestRule.kt b/glean-core/android/src/main/java/mozilla/telemetry/glean/testing/GleanTestRule.kt index 485c3d8bf4..5977cf918d 100644 --- a/glean-core/android/src/main/java/mozilla/telemetry/glean/testing/GleanTestRule.kt +++ b/glean-core/android/src/main/java/mozilla/telemetry/glean/testing/GleanTestRule.kt @@ -11,6 +11,8 @@ import androidx.work.testing.WorkManagerTestInitHelper import mozilla.telemetry.glean.BuildInfo import mozilla.telemetry.glean.Glean import mozilla.telemetry.glean.config.Configuration +import mozilla.telemetry.glean.private.NoReasonCodes +import mozilla.telemetry.glean.private.PingType import mozilla.telemetry.glean.private.TimeUnit import mozilla.telemetry.glean.scheduler.MetricsPingScheduler import mozilla.telemetry.glean.utils.getISOTimeString @@ -68,6 +70,37 @@ class GleanTestRule( mps.updateSentDate(getISOTimeString(fakeNow, truncateTo = TimeUnit.DAY)) + PingType( + name = "store1", + includeClientId = true, + sendIfEmpty = false, + preciseTimestamps = true, + includeInfoSections = true, + enabled = true, + schedulesPings = emptyList(), + reasonCodes = emptyList(), + ) + PingType( + name = "store2", + includeClientId = true, + sendIfEmpty = false, + preciseTimestamps = true, + includeInfoSections = true, + enabled = true, + schedulesPings = emptyList(), + reasonCodes = emptyList(), + ) + PingType( + name = "store3", + includeClientId = true, + sendIfEmpty = false, + preciseTimestamps = true, + includeInfoSections = true, + enabled = true, + schedulesPings = emptyList(), + reasonCodes = emptyList(), + ) + Glean.resetGlean( context = context, config = configToUse, diff --git a/glean-core/android/src/test/java/mozilla/telemetry/glean/pings/CustomPingTest.kt b/glean-core/android/src/test/java/mozilla/telemetry/glean/pings/CustomPingTest.kt index e851c80f72..c6c90a2f62 100644 --- a/glean-core/android/src/test/java/mozilla/telemetry/glean/pings/CustomPingTest.kt +++ b/glean-core/android/src/test/java/mozilla/telemetry/glean/pings/CustomPingTest.kt @@ -161,6 +161,21 @@ class CustomPingTest { val pingName = "custom-events-1" + // Define a new custom ping inline. + // This will register the ping as well. + // Ususally this happens in user code by calling `Glean.registerPings(Pings)` + @Suppress("UNUSED_VARIABLE") + val customPing = PingType( + name = pingName, + includeClientId = true, + sendIfEmpty = true, + preciseTimestamps = true, + includeInfoSections = true, + enabled = true, + schedulesPings = emptyList(), + reasonCodes = emptyList(), + ) + // Define a 'click' event val click = EventMetricType( CommonMetricData( @@ -178,21 +193,6 @@ class CustomPingTest { // We need to simulate that the app is shutdown and all resources are freed. Glean.testDestroyGleanHandle() - // Define a new custom ping inline. - // This will register the ping as well. - // Ususally this happens in user code by calling `Glean.registerPings(Pings)` - @Suppress("UNUSED_VARIABLE") - val customPing = PingType( - name = pingName, - includeClientId = true, - sendIfEmpty = true, - preciseTimestamps = true, - includeInfoSections = true, - enabled = true, - schedulesPings = emptyList(), - reasonCodes = emptyList(), - ) - // The PingUploadWorker might be queued for at-init reasons, so to ensure // init didn't submit this custom ping we submit it deliberately only once, // and assert that we didn't receive it twice. diff --git a/glean-core/ios/GleanTests/TestUtils.swift b/glean-core/ios/GleanTests/TestUtils.swift index 12c3bc9db6..bc2a406536 100644 --- a/glean-core/ios/GleanTests/TestUtils.swift +++ b/glean-core/ios/GleanTests/TestUtils.swift @@ -88,6 +88,37 @@ func resetGleanDiscardingInitialPings(testCase: XCTestCase, let mps = MetricsPingScheduler(true) mps.updateSentDate(Date()) + _ = Ping( + name: "store1", + includeClientId: true, + sendIfEmpty: false, + preciseTimestamps: true, + includeInfoSections: true, + enabled: true, + schedulesPings: [], + reasonCodes: [] + ) + _ = Ping( + name: "store2", + includeClientId: true, + sendIfEmpty: false, + preciseTimestamps: true, + includeInfoSections: true, + enabled: true, + schedulesPings: [], + reasonCodes: [] + ) + _ = Ping( + name: "store3", + includeClientId: true, + sendIfEmpty: false, + preciseTimestamps: true, + includeInfoSections: true, + enabled: true, + schedulesPings: [], + reasonCodes: [] + ) + Glean.shared.resetGlean(configuration: configuration, clearStores: clearStores) testCase.waitForExpectations(timeout: 5.0) { error in diff --git a/glean-core/python/tests/conftest.py b/glean-core/python/tests/conftest.py index ee74ac95c7..9d1429d4a3 100644 --- a/glean-core/python/tests/conftest.py +++ b/glean-core/python/tests/conftest.py @@ -15,6 +15,7 @@ from glean import config from glean import testing from glean import __version__ as glean_version +from glean.metrics import PingType # This defines the location of the JSON schema used to validate the pings # created during unit testing. This uses the vendored schema. @@ -30,6 +31,33 @@ # This will be run before every test in the entire test suite def pytest_runtest_setup(item): + PingType( + name="store1", + include_client_id=True, + send_if_empty=False, + precise_timestamps=True, + include_info_sections=True, + schedules_pings=[], + reason_codes=[], + ) + PingType( + name="store2", + include_client_id=True, + send_if_empty=False, + precise_timestamps=True, + include_info_sections=True, + schedules_pings=[], + reason_codes=[], + ) + PingType( + name="store3", + include_client_id=True, + send_if_empty=False, + precise_timestamps=True, + include_info_sections=True, + schedules_pings=[], + reason_codes=[], + ) testing.reset_glean(application_id="glean-python-test", application_version=glean_version) diff --git a/glean-core/rlb/examples/crashing-threads.rs b/glean-core/rlb/examples/crashing-threads.rs index bf96f44f1d..404476317e 100644 --- a/glean-core/rlb/examples/crashing-threads.rs +++ b/glean-core/rlb/examples/crashing-threads.rs @@ -102,6 +102,7 @@ fn main() { root.path().to_path_buf() }; + _ = &*PrototypePing; let cfg = ConfigurationBuilder::new(true, data_path, "org.mozilla.glean_core.example") .with_server_endpoint("invalid-test-host") .with_use_core_mps(true) diff --git a/glean-core/rlb/examples/delayed-ping-data.rs b/glean-core/rlb/examples/delayed-ping-data.rs index d683bf4afa..1e772a1c9e 100644 --- a/glean-core/rlb/examples/delayed-ping-data.rs +++ b/glean-core/rlb/examples/delayed-ping-data.rs @@ -85,6 +85,7 @@ fn main() { let data_path = PathBuf::from(args.next().expect("need data path")); let state = args.next().unwrap_or_default(); + _ = &*PrototypePing; let uploader = MovingUploader::new(data_path.clone()); let cfg = ConfigurationBuilder::new(true, data_path, "glean.pingflush") .with_server_endpoint("invalid-test-host") diff --git a/glean-core/rlb/examples/long-running.rs b/glean-core/rlb/examples/long-running.rs index 15e001772a..dda7037180 100644 --- a/glean-core/rlb/examples/long-running.rs +++ b/glean-core/rlb/examples/long-running.rs @@ -50,6 +50,7 @@ fn main() { let data_path = PathBuf::from(args.next().expect("need data path")); + _ = &*PrototypePing; let cfg = ConfigurationBuilder::new(true, data_path, "glean.longrunning") .with_server_endpoint("invalid-test-host") .with_use_core_mps(false) diff --git a/glean-core/rlb/examples/ping-lifetime-flush.rs b/glean-core/rlb/examples/ping-lifetime-flush.rs index 2aedbe20bd..660183833c 100644 --- a/glean-core/rlb/examples/ping-lifetime-flush.rs +++ b/glean-core/rlb/examples/ping-lifetime-flush.rs @@ -86,6 +86,7 @@ fn main() { let data_path = PathBuf::from(args.next().expect("need data path")); let state = args.next().unwrap_or_default(); + _ = &*PrototypePing; let uploader = MovingUploader::new(data_path.clone()); let cfg = ConfigurationBuilder::new(true, data_path, "glean.pingflush") .with_server_endpoint("invalid-test-host") diff --git a/glean-core/rlb/examples/prototype.rs b/glean-core/rlb/examples/prototype.rs index be0b53ed9f..774634520c 100644 --- a/glean-core/rlb/examples/prototype.rs +++ b/glean-core/rlb/examples/prototype.rs @@ -43,6 +43,7 @@ fn main() { root.path().to_path_buf() }; + _ = &*PrototypePing; let cfg = ConfigurationBuilder::new(true, data_path, "org.mozilla.glean_core.example") .with_server_endpoint("invalid-test-host") .with_use_core_mps(true) diff --git a/glean-core/rlb/src/common_test.rs b/glean-core/rlb/src/common_test.rs index fdb7cfadbf..12c460b3bb 100644 --- a/glean-core/rlb/src/common_test.rs +++ b/glean-core/rlb/src/common_test.rs @@ -2,6 +2,7 @@ // 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 crate::private::PingType; use crate::ClientInfoMetrics; use crate::{Configuration, ConfigurationBuilder}; use std::sync::{Mutex, MutexGuard}; @@ -45,6 +46,8 @@ pub(crate) fn new_glean( .build(), }; + _ = PingType::new("store1", true, true, true, true, true, vec![], vec![]); + crate::test_reset_glean(cfg, ClientInfoMetrics::unknown(), clear_stores); dir } diff --git a/glean-core/rlb/tests/common/mod.rs b/glean-core/rlb/tests/common/mod.rs index 67f010ff6b..26b0ae9842 100644 --- a/glean-core/rlb/tests/common/mod.rs +++ b/glean-core/rlb/tests/common/mod.rs @@ -8,7 +8,7 @@ use std::{panic, process}; -use glean::{ClientInfoMetrics, Configuration}; +use glean::{private::PingType, ClientInfoMetrics, Configuration}; /// Initialize the env logger for a test environment. /// @@ -48,5 +48,6 @@ pub fn initialize(cfg: Configuration) { locale: Some("xx-XX".to_string()), }; + _ = PingType::new("store1", true, true, true, true, true, vec![], vec![]); glean::initialize(cfg, client_info); } diff --git a/glean-core/rlb/tests/init_fails.rs b/glean-core/rlb/tests/init_fails.rs index 2ae4a91f02..920bcaf42a 100644 --- a/glean-core/rlb/tests/init_fails.rs +++ b/glean-core/rlb/tests/init_fails.rs @@ -60,6 +60,7 @@ fn init_fails() { let dir = tempfile::tempdir().unwrap(); let tmpname = dir.path().to_path_buf(); + _ = &*pings::validation; let cfg = ConfigurationBuilder::new(true, tmpname, "") .with_server_endpoint("invalid-test-host") .build(); diff --git a/glean-core/rlb/tests/simple.rs b/glean-core/rlb/tests/simple.rs index d5c6a5244c..a9360eeb2d 100644 --- a/glean-core/rlb/tests/simple.rs +++ b/glean-core/rlb/tests/simple.rs @@ -60,6 +60,7 @@ fn simple_lifecycle() { let dir = tempfile::tempdir().unwrap(); let tmpname = dir.path().to_path_buf(); + _ = &*pings::validation; let cfg = ConfigurationBuilder::new(true, tmpname, "firefox-desktop") .with_server_endpoint("invalid-test-host") .build(); diff --git a/glean-core/src/lib_unit_tests.rs b/glean-core/src/lib_unit_tests.rs index 7ea320858a..eff5184c29 100644 --- a/glean-core/src/lib_unit_tests.rs +++ b/glean-core/src/lib_unit_tests.rs @@ -7,6 +7,7 @@ use std::collections::HashSet; +use internal_pings::InternalPings; use serde_json::json; use super::*; @@ -19,7 +20,15 @@ pub fn new_glean(tempdir: Option) -> (Glean, tempfile::TempDi None => tempfile::tempdir().unwrap(), }; let tmpname = dir.path().display().to_string(); - let glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true); + let mut glean = Glean::with_options(&tmpname, GLOBAL_APPLICATION_ID, true, true); + // Register the builtin pings as enabled. + _ = InternalPings::new(true); + + // store{1, 2} is used throughout tests + let ping = PingType::new_internal("store1", true, false, true, true, true, vec![], vec![]); + glean.register_ping_type(&ping); + let ping = PingType::new_internal("store2", true, false, true, true, true, vec![], vec![]); + glean.register_ping_type(&ping); (glean, dir) } diff --git a/glean-core/tests/common/mod.rs b/glean-core/tests/common/mod.rs index 7bc08436df..5e99d4c51a 100644 --- a/glean-core/tests/common/mod.rs +++ b/glean-core/tests/common/mod.rs @@ -5,7 +5,7 @@ // #[allow(dead_code)] is required on this module as a workaround for // https://github.com/rust-lang/rust/issues/46379 #![allow(dead_code)] -use glean_core::{Glean, Result}; +use glean_core::{Glean, PingType, Result}; use std::fs::{read_dir, File}; use std::io::{BufRead, BufReader}; @@ -68,7 +68,13 @@ pub fn new_glean(tempdir: Option) -> (Glean, tempfile::TempDi ping_lifetime_threshold: 0, ping_lifetime_max_time: 0, }; - let glean = Glean::new(cfg).unwrap(); + let mut glean = Glean::new(cfg).unwrap(); + + // store{1,2} is used throughout tests + let ping = PingType::new("store1", true, false, true, true, true, vec![], vec![]); + glean.register_ping_type(&ping); + let ping = PingType::new("store2", true, false, true, true, true, vec![], vec![]); + glean.register_ping_type(&ping); (glean, dir) } diff --git a/glean-core/tests/event.rs b/glean-core/tests/event.rs index 43a3c9cda1..075751f218 100644 --- a/glean-core/tests/event.rs +++ b/glean-core/tests/event.rs @@ -568,7 +568,9 @@ fn with_event_timestamps() { ping_lifetime_threshold: 0, ping_lifetime_max_time: 0, }; - let glean = Glean::new(cfg).unwrap(); + let mut glean = Glean::new(cfg).unwrap(); + let ping = PingType::new("store1", true, false, true, true, true, vec![], vec![]); + glean.register_ping_type(&ping); let store_name = "store1"; let event = EventMetric::new(