Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

In tests register all pings by instantiating them #3002

Merged
merged 2 commits into from
Nov 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .swiftlint.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -68,6 +70,37 @@ class GleanTestRule(

mps.updateSentDate(getISOTimeString(fakeNow, truncateTo = TimeUnit.DAY))

PingType<NoReasonCodes>(
name = "store1",
includeClientId = true,
sendIfEmpty = false,
preciseTimestamps = true,
includeInfoSections = true,
enabled = true,
schedulesPings = emptyList(),
reasonCodes = emptyList(),
)
PingType<NoReasonCodes>(
name = "store2",
includeClientId = true,
sendIfEmpty = false,
preciseTimestamps = true,
includeInfoSections = true,
enabled = true,
schedulesPings = emptyList(),
reasonCodes = emptyList(),
)
PingType<NoReasonCodes>(
name = "store3",
includeClientId = true,
sendIfEmpty = false,
preciseTimestamps = true,
includeInfoSections = true,
enabled = true,
schedulesPings = emptyList(),
reasonCodes = emptyList(),
)

Glean.resetGlean(
context = context,
config = configToUse,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ class GleanTest {
category = "telemetry",
lifetime = Lifetime.PING,
name = "string_metric",
sendInPings = listOf("default"),
sendInPings = listOf("store1"),
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<NoReasonCodes>(
name = pingName,
includeClientId = true,
sendIfEmpty = true,
preciseTimestamps = true,
includeInfoSections = true,
enabled = true,
schedulesPings = emptyList(),
reasonCodes = emptyList(),
)

// Define a 'click' event
val click = EventMetricType<NoExtras>(
CommonMetricData(
Expand All @@ -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<NoReasonCodes>(
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.
Expand Down
31 changes: 31 additions & 0 deletions glean-core/ios/GleanTests/TestUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,37 @@ func resetGleanDiscardingInitialPings(testCase: XCTestCase,
let mps = MetricsPingScheduler(true)
mps.updateSentDate(Date())

_ = Ping<NoReasonCodes>(
name: "store1",
includeClientId: true,
sendIfEmpty: false,
preciseTimestamps: true,
includeInfoSections: true,
enabled: true,
schedulesPings: [],
reasonCodes: []
)
_ = Ping<NoReasonCodes>(
name: "store2",
includeClientId: true,
sendIfEmpty: false,
preciseTimestamps: true,
includeInfoSections: true,
enabled: true,
schedulesPings: [],
reasonCodes: []
)
_ = Ping<NoReasonCodes>(
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
Expand Down
28 changes: 28 additions & 0 deletions glean-core/python/tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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)


Expand Down
34 changes: 17 additions & 17 deletions glean-core/python/tests/data/core.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ telemetry:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

core_ping:
Expand All @@ -37,7 +37,7 @@ core_ping:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

created:
Expand All @@ -52,7 +52,7 @@ core_ping:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

sessions:
Expand All @@ -66,7 +66,7 @@ core_ping:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

durations:
Expand All @@ -82,7 +82,7 @@ core_ping:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

searches:
Expand All @@ -105,7 +105,7 @@ core_ping:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

flash_usage:
Expand All @@ -120,7 +120,7 @@ core_ping:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

default_browser:
Expand All @@ -134,7 +134,7 @@ core_ping:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

environment:
Expand All @@ -149,7 +149,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

os:
Expand All @@ -163,7 +163,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

os_version:
Expand All @@ -177,7 +177,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

device:
Expand All @@ -194,7 +194,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

arch:
Expand All @@ -221,7 +221,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

default_search:
Expand All @@ -236,7 +236,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

display_version:
Expand All @@ -251,7 +251,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

distribution_id:
Expand All @@ -266,7 +266,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

campaign_id:
Expand All @@ -281,7 +281,7 @@ environment:
notification_emails:
- [email protected]
send_in_pings:
- core
- store1
expires: 2100-01-01

event_example:
Expand Down
1 change: 1 addition & 0 deletions glean-core/rlb/examples/crashing-threads.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions glean-core/rlb/examples/delayed-ping-data.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions glean-core/rlb/examples/long-running.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions glean-core/rlb/examples/ping-lifetime-flush.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
Expand Down
1 change: 1 addition & 0 deletions glean-core/rlb/examples/prototype.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions glean-core/rlb/src/common_test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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};
Expand Down Expand Up @@ -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
}
Loading
Loading