Skip to content

Commit

Permalink
Kotlin: ensure test triggers _some_ work
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
badboy committed May 4, 2021
1 parent 5f9ece7 commit cdba52c
Showing 1 changed file with 5 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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")
)

Expand Down Expand Up @@ -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.
Expand Down

0 comments on commit cdba52c

Please sign in to comment.