Closed Bug 1552114 Opened 7 years ago Closed 6 years ago

Integrating Glean in a product might break its unit tests

Categories

(Data Platform and Tools :: Glean: SDK, enhancement, P3)

enhancement

Tracking

(Not tracked)

RESOLVED WORKSFORME

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.

Assignee: nobody → alessio.placitelli
Priority: -- → P1

(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.initializeTestWorkManager in 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.

Assignee: alessio.placitelli → nobody
Priority: P1 → P3
Whiteboard: [telemetry:glean-rs:backlog]

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?

Yes, I think we can close this as WORKSFORME and revisit.

Status: NEW → RESOLVED
Closed: 6 years ago
Resolution: --- → WORKSFORME
You need to log in before you can comment on or make changes to this bug.