question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Espresso isIdleNow() error

See original GitHub issue

I have a situation and I’m not sure if it’s a bug or if I’m doing something wrong. The project I’m working on has a fairly long series of tests, each of which creates and registers an OkHttp3IdlingResource in @Before and unregisters it in @After. Each class passes individually, but if I run the complete set, at some point I start getting the Espresso error: “isIdleNow() is returning true, but a message indicating that the resource has transitioned from busy to idle was never sent”

I’m wondering if there’s a race condition with the dispatcher idle callback, since isIdleNow() queries the dispatcher directly, and the dispatcher callback is a Runnable. Following the pattern of a few other IdleResource examples:

http://stackoverflow.com/questions/28674899/isidlenow-is-returning-true-but-a-message-indicating-that-the-resource-has-tr http://blog.sqisland.com/2015/04/espresso-custom-idling-resource.html

I revised isIdleNow() to:

  @Override public boolean isIdleNow() {
    boolean idle = (dispatcher.runningCallsCount() == 0);
    if (idle && callback != null) callback.onTransitionToIdle();
    return idle;
  }

Obviously, that makes the problem go away. If you think that’s appropriate, I’d be happy to contribute the code, but if I’m just using it wrong, I’d be happy for a better solution.

Issue Analytics

  • State:open
  • Created 6 years ago
  • Reactions:28
  • Comments:5

github_iconTop GitHub Comments

3reactions
jonreevecommented, Dec 19, 2019

It’s worth noting that while this fix prevents Espresso complaining, it works around what it’s trying to tell you: the IdlingResource contract hasn’t been properly fulfilled, as the callback isn’t getting called as soon as this resource is idle. This can lead to tests waiting longer than they need to before continuing, which may also lead to them missing things on the UI that disappear quickly.

If you’re getting the error this describes, I’d make sure that you’re only setting the idleCallback on the OkHttp dispatcher once, and not accidentally overwriting / otherwise clearing it. That’s what this error indicated in our case. That happened because we created one of these per OkHttp client, and didn’t consider that those clients actually shared the same Dispatcher.

2reactions
georgiecaseycommented, Jan 13, 2018

Thanks as well @JimEH42g, it fixed my problem as well. Are you thinking of submitting a pull request?

Read more comments on GitHub >

github_iconTop Results From Across the Web

isIdleNow() is returning true, but a message indicating that the ...
I'm trying to write a test in Espresso for my Android application, and I have a problem with Idle. If my isIdleNow() looks...
Read more >
CountingIdlingResource - Android Developers
public boolean isIdleNow(). Returns true if resource is currently idle. Espresso will always call this method from the main thread, ...
Read more >
android.support.test.espresso.IdlingResource.isIdleNow java ...
elapsedRealtime(); do { if (idlingResource.isIdleNow()) { break; } SystemClock.sleep(100); } while (SystemClock.elapsedRealtime() - l > timeout); }.
Read more >
Hello, espresso! Part 4 Working with Idling resources
When we invoke onView() , espresso waits and checks for the below ... NOTE: We'll get below error if we try to run...
Read more >
Idling resources in Espresso | Repeato
The isIdleNow() method is the kernel and the most important part of IdlingResource. It gives IdlingResourceRegistry information about the ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found