title: Espresso Test Fail due to App not Idle Exception: The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED
body: <p>My Espresso test is working fine with Espresso version <code>2.2.2</code> but When I update my studio to latest one and applied migration rule test going to fail and required to update the version.<br>
  <strong>library using</strong> </p>
  
  <pre><code>androidTestImplementation'com.android.support.test.espresso:espresso-core:3.0.1'
      implementation 'com.android.support.test.espresso:espresso-idling-resource:3.0.1'
      androidTestImplementation 'junit:junit:4.12'
      androidTestImplementation 'com.android.support.test:runner:1.0.1'
      androidTestCompile 'com.android.support.test:rules:1.0.1'
      androidTestImplementation "com.android.support:support-annotations:${support}"
      implementation fileTree(include: ['*.jar'], dir: 'libs')
  </code></pre>
  
  <p>For Idling resource during testing I am using the <a href="https://github.com/googlesamples/android-testing/tree/master/ui/espresso/IdlingResourceSample" rel="nofollow noreferrer">IdlingResourceSample</a> also I also tried <a href="https://github.com/chiuki/espresso-samples/tree/master/idling-resource-intent-service" rel="nofollow noreferrer">idling-resource-intent-service</a>  As I am using <code>IntentService</code> and <code>BroadcastReceiver</code>.<br>
  As There is issue in <code>Espresso</code> <a href="https://issuetracker.google.com/issues/65568629" rel="nofollow noreferrer"> Espresso.onIdle</a> &amp; <a href="https://issuetracker.google.com/issues/65576174" rel="nofollow noreferrer">Espresso IdlingResourceRegistry.sync</a> which is already reported and will fix in next release. I use <code>IdlingRegistry</code> for registering. but still I am getting <code>AppNotIdleException</code><br>
  <strong>Log Cat</strong></p>
  
  <pre><code>android.support.test.espresso.AppNotIdleException: Looped for 35 iterations over 60 SECONDS. The following Idle Conditions failed ASYNC_TASKS_HAVE_IDLED.
  at dalvik.system.VMStack.getThreadStackTrace(Native Method)
  at java.lang.Thread.getStackTrace(Thread.java:1538)
  at android.support.test.espresso.base.DefaultFailureHandler.getUserFriendlyError(DefaultFailureHandler.java:90)
  at android.support.test.espresso.base.DefaultFailureHandler.handle(DefaultFailureHandler.java:52)
  at android.support.test.espresso.ViewInteraction.waitForAndHandleInteractionResults(ViewInteraction.java:312)
  at android.support.test.espresso.ViewInteraction.check(ViewInteraction.java:291)
  at com.company.project.InstrumentedDeepLinkTest.setDeepLinkUri(InstrumentedDeepLinkTest.java:107)
  at java.lang.reflect.Method.invoke(Native Method)
  at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
  at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
  at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
  at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
  at android.support.test.rule.ActivityTestRule$ActivityStatement.evaluate(ActivityTestRule.java:433)
  at org.junit.rules.RunRules.evaluate(RunRules.java:20)
  at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:78)
  at org.junit.runners.BlockJUnit4ClassRunner.runChild(BlockJUnit4ClassRunner.java:57)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.junit.runners.Suite.runChild(Suite.java:128)
  at org.junit.runners.Suite.runChild(Suite.java:27)
  at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
  at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
  at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
  at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
  at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
  at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:137)
  at org.junit.runner.JUnitCore.run(JUnitCore.java:115)
  at android.support.test.internal.runner.TestExecutor.execute(TestExecutor.java:58)
  at android.support.test.runner.AndroidJUnitRunner.onStart(AndroidJUnitRunner.java:375)
  at android.app.Instrumentation$InstrumentationThread.run(Instrumentation.java:2075) 
  </code></pre>
  
  <p>I disabled already animations from <code>developer Options</code></p>
  
  <p>After Analyzing which <code>AsyncTask</code> is keeping my <code>App</code> busy, I got the <code>thread pool</code> having many <code>AsyncTask</code> related to <code>sun.misc.Unsafe.park(Unsafe.java:299)</code>.<br>
  <strong>Thread Pool</strong></p>
  
  <pre><code>AsyncTask #9: WAITING
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.lang.Object.wait(Native Method)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.lang.Thread.parkFor$(Thread.java:1220)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  sun.misc.Unsafe.park(Unsafe.java:299)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.locks.LockSupport.park(LockSupport.java:158)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.locks.AbstractQueuedSynchronizer$ConditionObject.await(AbstractQueuedSynchronizer.java:2013)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.LinkedBlockingQueue.take(LinkedBlockingQueue.java:410)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.ThreadPoolExecutor.getTask(ThreadPoolExecutor.java:1036)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1098)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:588)
  02-21 16:16:39.955 1611-1670/com.myCompany.MyProject W/System.err:  java.lang.Thread.run(Thread.java:818)
  </code></pre>