Integrating Glean in a product might break its unit tests
Categories
(Data Platform and Tools :: Glean: SDK, enhancement, P3)
Tracking
(Not tracked)
People
(Reporter: Dexter, Unassigned)
Details
(Whiteboard: [telemetry:glean-rs:backlog])
While integrating with firefox-tv, we found that sometimes unrelated tests were intermittently (interkittently, by the Glean lingo) failing with the following error:
java.lang.IllegalStateException: WorkManager is not initialized properly. The most likely cause is that you disabled WorkManagerInitializer in your manifest but forgot to call WorkManager#initialize in your Application#onCreate or a ContentProvider.
at androidx.work.WorkManager.getInstance(WorkManager.java:141)
at mozilla.components.service.glean.scheduler.MetricsPingScheduler.schedulePingCollection$service_glean_release(MetricsPingScheduler.kt:76)
at mozilla.components.service.glean.scheduler.MetricsPingScheduler.startupCheck(MetricsPingScheduler.kt:198)
at mozilla.components.service.glean.GleanInternalAPI.initialize(Glean.kt:113)
at mozilla.components.service.glean.GleanInternalAPI.initialize$default(Glean.kt:81)
at org.mozilla.tv.firefox.FirefoxApplication.initGlean(FirefoxApplication.kt:80)
This was failing because Glean ping schedulers (i.e. metrics ping scheduler), in addition to the ping uploader, are using the WorkManager. Schedulers are not turned off when upload is disabled, for consistency with the Glean internals and with the behaviours on other platforms. In general, this shouldn't be a problem. However WorkManager it's disabled in tests and requires special initialization (i.e. calling WorkManagerTestInitHelper.initializeTestWorkManager), which the product need to perform in addition to setting ping upload to off. See the firefox-tv fix.
This is a bit weird: we should find a solution to not force products to call WorkManagerTestInitHelper.initializeTestWorkManager in their tests or, at the very least, document this behaviour.
| Reporter | ||
Updated•7 years ago
|
| Reporter | ||
Comment 1•7 years ago
|
||
(In reply to Alessio Placitelli [:Dexter] from comment #0)
This is a bit weird: we should find a solution to not force products to call
WorkManagerTestInitHelper.initializeTestWorkManagerin their tests or, at the very least, document this behaviour.
If we bump the version of WorkManager to 2.1.0-alpha01, we might be able to perform on-demand initialization, in tests. It's a bit of an unknown, as the Application class of the tests would need to somehow implement some WorkManager related interface. We could do this in our own tests, but definitely not in 3rd party tests.
| Reporter | ||
Updated•6 years ago
|
Comment 2•6 years ago
|
||
Since we provide the call to WorkManagerTestInitHelper.initializeTestWorkManager in the GleanTestRule, and we recommend using the GleanTestRule in both the Testing Metrics section and in the example for Testing Custom Pings, can we close this as FIXED?
| Reporter | ||
Comment 3•6 years ago
|
||
Yes, I think we can close this as WORKSFORME and revisit.
Description
•