-
Notifications
You must be signed in to change notification settings - Fork 119
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Bug 1844533 - Fix Glean ping uploading from background process
When Glean attempted to schedule an upload task on the WorkManager from a background process it would get the main-process Glean when the task was executed. Since the main-process Glean didn't have the data directory from the background process, it would not find the ping to be able to upload it. This changes the uploader to run on the internal Glean Dispatcher when it is being run from a background service or process and continues to rely on WorkManager for the main process execution.
- Loading branch information
Showing
10 changed files
with
126 additions
and
74 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
58 changes: 58 additions & 0 deletions
58
...ndroid/app/src/androidTest/java/org/mozilla/samples/gleancore/pings/BackgroundPingTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
/* 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 http://mozilla.org/MPL/2.0/. */ | ||
|
||
package org.mozilla.samples.gleancore.pings | ||
|
||
import android.content.Context | ||
import android.content.Intent | ||
import androidx.test.core.app.ApplicationProvider | ||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
import androidx.test.rule.ServiceTestRule | ||
import mozilla.telemetry.glean.testing.GleanTestLocalServer | ||
import org.junit.Assert.assertFalse | ||
import org.junit.Assert.assertNotNull | ||
import org.junit.Assert.assertTrue | ||
import org.junit.Ignore | ||
import org.junit.Rule | ||
import org.junit.Test | ||
import org.junit.runner.RunWith | ||
import org.mozilla.samples.gleancore.SampleBackgroundProcess | ||
|
||
@RunWith(AndroidJUnit4::class) | ||
@Ignore | ||
class BackgroundPingTest { | ||
private val server = createMockWebServer() | ||
|
||
@get:Rule | ||
val serviceRule: ServiceTestRule = ServiceTestRule() | ||
|
||
@get:Rule | ||
val gleanRule = GleanTestLocalServer(context, server.port) | ||
|
||
private val context: Context | ||
get() = ApplicationProvider.getApplicationContext() | ||
|
||
@Test | ||
fun validateBackgroundPing() { | ||
val serviceIntent = Intent( | ||
context, | ||
SampleBackgroundProcess::class.java, | ||
) | ||
serviceRule.startService(serviceIntent) | ||
|
||
val backgroundPing = waitForPingContent("background", "started", server) | ||
assertNotNull(backgroundPing) | ||
|
||
val metrics = backgroundPing?.getJSONObject("metrics") | ||
|
||
val counters = metrics?.getJSONObject("counter") | ||
assertTrue(counters?.getJSONObject("custom.bg_counter")?.getLong("value") == 1L) | ||
|
||
// Make sure there's no errors. | ||
val errors = metrics?.optJSONObject("labeled_counter")?.keys() | ||
errors?.forEach { | ||
assertFalse(it.startsWith("glean.error.")) | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters