Skip to content
Latchkey

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.

Espresso
androidx.test.espresso.IdlingResourceTimeoutException: Wait for
[OkHttpIdlingResource] to become idle timed out

Common 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

  1. Point the app at a fast local mock so tracked async work completes.
  2. Raise the master idle timeout for CI hardware if needed.
  3. Unregister IdlingResources after each test.
BaseTest.kt
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.

Frequently asked questions

What causes ""IdlingResourceTimeoutException""?
A network call or background task the IdlingResource tracks stalled, so it never transitioned to idle before the timeout.
How do I fix "IdlingResourceTimeoutException"?
Stub slow work and raise the idle timeout

Related guides

References

Latchkey auto-heals failures like this one - detected, fixed, and retried without you. Start free → 30-day trial · No credit card