android / android/android-test

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

Open
#255 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Java
Stars
1.2k
Forks
342
Avg merge
11h 29m
Merged PRs (30d)
2

Description

### 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.

Contributor guide

Open the contributing guide

Research direction

Start with ThreadPoolExecutorExtractor.java and inspect the referenced support-library THREAD_POOL_EXECUTOR alongside ModernAsyncTask. Then trace LoaderManagerImpl.LoaderViewModel.hasRunningLoaders() and reproduce the content-resolver insertion scenario described in the issue. Done means Espresso reliably waits for updated loader data and the corresponding checks pass without intermittent failures.

Written by the indexing model from the issue text.

Assessment

Tech stack
java
Domain
mobile-dev, testing-qa
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.