android - Espresso freezing on view with looping animation -
i have view in element animated following in infinite loop:
<translate android:fromxdelta="0%" android:toxdelta="100%" android:duration="10000" android:repeatcount="-1" android:repeatmode="reverse"/>
when espresso opens activity, it's able perform operations freezes. suppose espresso waiting ui thread become idle never happens in case.
is way me test view implement mechanism disable animations? have class handle animations, mocked tests. or build time conditionals.
edit: have yet create sample project attempt recreate issue, here further details in meantime:
1) using jake wharton's activityrule
have activity automatically launched (https://gist.github.com/jakewharton/1c2f2cadab2ddd97f9fb).
2) test:
onview(withid(r.id.btn_yes)).perform(click());
3) here complete stack trace. note appnotidleexception
:
running tests test running started android.support.test.espresso.performexception: error performing 'single click' on view 'with id: com.myapp:id/btn_yes'. @ android.support.test.espresso.performexception$builder.build(performexception.java:83) @ android.support.test.espresso.base.defaultfailurehandler.getuserfriendlyerror(defaultfailurehandler.java:70) @ android.support.test.espresso.base.defaultfailurehandler.handle(defaultfailurehandler.java:53) @ android.support.test.espresso.viewinteraction.runsynchronouslyonuithread(viewinteraction.java:185) @ android.support.test.espresso.viewinteraction.doperform(viewinteraction.java:115) @ android.support.test.espresso.viewinteraction.perform(viewinteraction.java:87) @ com.myapp.espresso.myactivitytest.yesbuttontest(myactivitytest.java:53) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ org.junit.runners.model.frameworkmethod$1.runreflectivecall(frameworkmethod.java:45) @ org.junit.internal.runners.model.reflectivecallable.run(reflectivecallable.java:15) @ org.junit.runners.model.frameworkmethod.invokeexplosively(frameworkmethod.java:42) @ org.junit.internal.runners.statements.invokemethod.evaluate(invokemethod.java:20) @ com.myapp.espresso.activityrule$2.evaluate(activityrule.java:129) @ org.junit.rules.runrules.evaluate(runrules.java:18) @ org.junit.runners.parentrunner.runleaf(parentrunner.java:263) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:68) @ org.junit.runners.blockjunit4classrunner.runchild(blockjunit4classrunner.java:47) @ org.junit.runners.parentrunner$3.run(parentrunner.java:231) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:60) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:229) @ org.junit.runners.parentrunner.access$000(parentrunner.java:50) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:222) @ org.junit.runners.parentrunner.run(parentrunner.java:300) @ org.junit.runners.suite.runchild(suite.java:128) @ org.junit.runners.suite.runchild(suite.java:24) @ org.junit.runners.parentrunner$3.run(parentrunner.java:231) @ org.junit.runners.parentrunner$1.schedule(parentrunner.java:60) @ org.junit.runners.parentrunner.runchildren(parentrunner.java:229) @ org.junit.runners.parentrunner.access$000(parentrunner.java:50) @ org.junit.runners.parentrunner$2.evaluate(parentrunner.java:222) @ org.junit.runners.parentrunner.run(parentrunner.java:300) @ org.junit.runner.junitcore.run(junitcore.java:157) @ org.junit.runner.junitcore.run(junitcore.java:136) @ android.support.test.runner.androidjunitrunner.onstart(androidjunitrunner.java:270) @ android.app.instrumentation$instrumentationthread.run(instrumentation.java:1837) caused by: android.support.test.espresso.appnotidleexception: looped 3580 iterations on 60 seconds. following idle conditions failed . @ android.support.test.espresso.idlingpolicy.handletimeout(idlingpolicy.java:61) @ android.support.test.espresso.base.uicontrollerimpl.loopuntil(uicontrollerimpl.java:471) @ android.support.test.espresso.base.uicontrollerimpl.loopuntil(uicontrollerimpl.java:402) @ android.support.test.espresso.base.uicontrollerimpl.injectmotionevent(uicontrollerimpl.java:226) @ android.support.test.espresso.action.motionevents.senddown(motionevents.java:78) @ android.support.test.espresso.action.tap.sendsingletap(tap.java:133) @ android.support.test.espresso.action.tap.access$100(tap.java:35) @ android.support.test.espresso.action.tap$1.sendtap(tap.java:40) @ android.support.test.espresso.action.generalclickaction.perform(generalclickaction.java:98) @ android.support.test.espresso.viewinteraction$1.run(viewinteraction.java:144) @ java.util.concurrent.executors$runnableadapter.call(executors.java:422) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(native method) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694)
4) stack traces when pausing execution of test while it's frozen:
thread #1:
"instr: android.support.test.runner.androidjunitrunner@4549" prio=5 waiting java.lang.thread.state: waiting blocks instr: android.support.test.runner.androidjunitrunner@4549 @ java.lang.object.wait(object.java:-1) @ java.lang.thread.parkfor(thread.java:1220) - locked <0x13a3> (a java.lang.object) @ sun.misc.unsafe.park(unsafe.java:299) @ java.util.concurrent.locks.locksupport.park(locksupport.java:157) @ java.util.concurrent.futuretask.awaitdone(futuretask.java:400) @ java.util.concurrent.futuretask.get(futuretask.java:162) @ android.support.test.espresso.viewinteraction.runsynchronouslyonuithread(viewinteraction.java:181) @ android.support.test.espresso.viewinteraction.doperform(viewinteraction.java:115) @ android.support.test.espresso.viewinteraction.perform(viewinteraction.java:87)
thread #2:
"main@4663" prio=5 runnable java.lang.thread.state: runnable @ android.view.threadedrenderer.nsyncanddrawframe(threadedrenderer.java:-1) @ android.view.threadedrenderer.draw(threadedrenderer.java:333) @ android.view.viewrootimpl.draw(viewrootimpl.java:2492) @ android.view.viewrootimpl.performdraw(viewrootimpl.java:2337) @ android.view.viewrootimpl.performtraversals(viewrootimpl.java:1968) @ android.view.viewrootimpl.dotraversal(viewrootimpl.java:1054) @ android.view.viewrootimpl$traversalrunnable.run(viewrootimpl.java:5779) @ android.view.choreographer$callbackrecord.run(choreographer.java:767) @ android.view.choreographer.docallbacks(choreographer.java:580) @ android.view.choreographer.doframe(choreographer.java:550) @ android.view.choreographer$framedisplayeventreceiver.run(choreographer.java:753) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.support.test.espresso.base.uicontrollerimpl.loopuntil(uicontrollerimpl.java:461) @ android.support.test.espresso.base.uicontrollerimpl.loopuntil(uicontrollerimpl.java:402) @ android.support.test.espresso.base.uicontrollerimpl.injectmotionevent(uicontrollerimpl.java:226) @ android.support.test.espresso.action.motionevents.senddown(motionevents.java:78) @ android.support.test.espresso.action.tap.sendsingletap(tap.java:133) @ android.support.test.espresso.action.tap.access$100(tap.java:35) @ android.support.test.espresso.action.tap$1.sendtap(tap.java:40) @ android.support.test.espresso.action.generalclickaction.perform(generalclickaction.java:98) @ android.support.test.espresso.viewinteraction$1.run(viewinteraction.java:144) @ java.util.concurrent.executors$runnableadapter.call(executors.java:422) @ java.util.concurrent.futuretask.run(futuretask.java:237) @ android.os.handler.handlecallback(handler.java:739) @ android.os.handler.dispatchmessage(handler.java:95) @ android.os.looper.loop(looper.java:135) @ android.app.activitythread.main(activitythread.java:5221) @ java.lang.reflect.method.invoke(method.java:-1) @ java.lang.reflect.method.invoke(method.java:372) @ com.android.internal.os.zygoteinit$methodandargscaller.run(zygoteinit.java:899) @ com.android.internal.os.zygoteinit.main(zygoteinit.java:694)
yes, problem having test due animation.
the solution can think of indeed turn off infinite animations.
in general idea turn off animations when running functional tests, introduce flakiness.
a bit of background:
the ui thread never idle espresso's perspective, because message queue contains event scheduled handling closer threshold used determine if thread idle.
when @ queueinterrogator
, can see it's determinequeuestate()
returns task_due_soon
when message queue contains event scheduled handling in less 16ms. uicontroller
continue execution when idle conditions fulfilled, in case of queueinterrogator
case if message queue empty or next message scheduled handling in 16ms or later.
animations invalidate view
transforming, , trigger new view hierarchy traversal choreographer
. , trigger message coming viewroot
choreographer
keeping ui thread message queue not idle.