Espresso "IdlingResource ... timed out" in CI
Espresso blocks until every registered IdlingResource is idle. If a resource stays busy past the master idle timeout, Espresso throws IdlingResourceTimeoutException. On CI a slow network or a never-completing task is the usual reason.
What this error means
A test fails with "androidx.test.espresso.IdlingResourceTimeoutException: Wait for [MyIdlingResource] to become idle timed out". It happens more on CI, where async work runs slower.
androidx.test.espresso.IdlingResourceTimeoutException: Wait for
[OkHttpIdlingResource] to become idle timed outCommon causes
The awaited async work never finished
A network call or background task the IdlingResource tracks stalled, so it never transitioned to idle before the timeout.
An IdlingResource that is never unregistered or is buggy
A resource that reports busy forever, or one left registered across tests, keeps Espresso waiting until it times out.
How to fix it
Stub slow work and raise the idle timeout
- Point the app at a fast local mock so tracked async work completes.
- Raise the master idle timeout for CI hardware if needed.
- Unregister IdlingResources after each test.
IdlingPolicies.setMasterPolicyTimeout(60, TimeUnit.SECONDS);
IdlingRegistry.getInstance().unregister(resource);Verify the resource actually reaches idle
Make sure the IdlingResource fires its callback when work finishes; a buggy resource that never signals idle will always time out.
How to prevent it
- Stub slow endpoints so tracked work completes in test.
- Unregister IdlingResources between tests.
- Raise the master idle timeout for slower CI when justified.