android / android/android-test

Espresso does not wait for androidx.loader.content.ModernAsyncTask

Offen
#255 2 Kommentare 0 Reaktionen 0 zugewiesene Personen Auf GitHub ansehen
Vorherrschende Sprache
Java
Sterne
1.2k
Forks
342
Ø Merge
11 Std. 29 Min.
Gemergte PRs (30 T.)
2

Beschreibung

### Description

After migrating to AndroidX, test execution became much less reliable. It appears that Espresso is no longer waiting for androidx.loader.content.AsyncTaskLoader to emit updated data to onLoadFinished() when tests use the content resolver to insert new data. I believe this problem may have at least two causes.

1. androidx.loader.app.LoaderManagerImpl.LoaderViewModel.hasRunningLoaders() only seems to return true up until the first value is emitted by a loader. Subsequent content change notifications aren't considered.
2. androidx.loader.content.ModernAsyncTask doesn't appear to be monitored by Espresso. THREAD_POOL_EXECUTOR from the support library version is [still referenced here](https://github.com/android/android-test/blob/master/espresso/core/java/androidx/test/espresso/base/ThreadPoolExecutorExtractor.java#L42).

### Steps to Reproduce

* Set up content provider and a basic activity that loads an entity with androidx.loader.content.AsyncTaskLoader and shows its content on screen.
* In a test, start an activity with the loader and then insert an entity into the database with the content resolver (also from the test).
* Use Espresso to check that the data has been rendered to a view.

### Expected Results

The data should be shown and Espresso checks should pass.

### Actual Results

Espresso usually passes but in rare instances it fails. Espresso waits for loaders to emit at least one value, even an initial null, but it continues immediately thereafter. This seems to be true even when there are pending content change notifications.

### AndroidX Test and Android OS Versions

androidx.test.espresso: 3.1.1
Android API: 28

### Link to a public git repo demonstrating the problem:

May be able to provide if needed.

Beitragsleitfaden

Beitragsleitfaden öffnen

Rechercherichtung

Beginne mit ThreadPoolExecutorExtractor.java und untersuche den referenzierten support-library THREAD_POOL_EXECUTOR zusammen mit ModernAsyncTask. Verfolge anschließend LoaderManagerImpl.LoaderViewModel.hasRunningLoaders() und reproduziere das im Issue beschriebene content-resolver-Einfügungsszenario. Als erledigt gilt die Aufgabe, wenn Espresso zuverlässig auf aktualisierte Loader-Daten wartet und die entsprechenden Prüfungen ohne intermittierende Fehler bestehen.

Vom Indexierungsmodell aus dem Issue-Text verfasst.

Bewertung

Tech-Stack
java
Bereich
mobile-dev, testing-qa
Issue-Typ
Bug
Schwierigkeit
4/5
Geschätzter Aufwand
3-5 Tage
Aktivitätsstatus
Veraltet
Klarheit
Größtenteils klar
Anfängerfreundlichkeit
35/100

Neue Issues direkt in Ihr Postfach

Eine kurze Übersicht über anfängerfreundliche GitHub-Issues.