From e2378d649ead9c5511d46f5d0ab27c81d3ddf04a Mon Sep 17 00:00:00 2001 From: Jan-Erik Rediger Date: Tue, 4 May 2021 15:06:49 +0200 Subject: [PATCH] Kotlin: ensure test triggers _some_ work This is required because of the changes made to ping.submit before and how it was used internally. Previously in event_database, when triggering startup event pings, we only checked if storing a ping did not fail. We did not check if any ping was actually submitted. So the code around it launched a task on the workmanager, which then subsequently checked and did nothing. The test ensured that, and triggering the work manager was just fine because there _was_ a pending task. With the changes we now return `true` if any ping was submitted. Or `false` if no event ping was submitted on startup. Now on startup no task was triggered and thus no workmanager can be triggered. That made the test fail because `triggerWorkManager` requires a task to be enqueued. We can force a task by also recording into the builtin "events" ping. It's a small hack, but allows us to test that late-registered pings with events are correctly skipped AND their events are deleted. --- .../mozilla/telemetry/glean/private/EventMetricTypeTest.kt | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/glean-core/android/src/test/java/mozilla/telemetry/glean/private/EventMetricTypeTest.kt b/glean-core/android/src/test/java/mozilla/telemetry/glean/private/EventMetricTypeTest.kt index 89b3deb320..95f3efc558 100644 --- a/glean-core/android/src/test/java/mozilla/telemetry/glean/private/EventMetricTypeTest.kt +++ b/glean-core/android/src/test/java/mozilla/telemetry/glean/private/EventMetricTypeTest.kt @@ -495,7 +495,7 @@ class EventMetricTypeTest { category = "telemetry", name = "test_event", lifetime = Lifetime.Ping, - sendInPings = listOf(pingName), + sendInPings = listOf(pingName, "events"), // also send in builtin ping allowedExtraKeys = listOf("someExtra") ) @@ -523,11 +523,14 @@ class EventMetricTypeTest { sendIfEmpty = false, reasonCodes = listOf()) - // Trigger worker task to upload the pings in the background + // Trigger worker task to upload the pings in the background. + // Because this also triggers the builtin "events" ping + // we should definitely get _something_. triggerWorkManager(context) // We can't properly test the absence of data, // but we can try to receive one and that causes an exception if there is none. + // We also get the "events" ping, which we'll simply ignore here. assertNull(waitForPingContent(pingName, null, server)) // Now try to manually submit the ping.