I want to control whether `delay(..)` reports IDLE...
# coroutines
z
I want to control whether
delay(..)
reports IDLE or not in an Espresso test dynamically at runtime. What would be the right way to handle this?. For example, if a
delay(..)
launched on
Dispatchers.Default
is currently suspended, I would like to be able to control at any point through the test whether the dispatcher should report idle or not
z
You could wrap the dispatchers you're injecting for your tests in ones that tracks delays as idling resources or something. I haven't tried this but it seems like it should work? For that matter, to be more general, you could also probably just wrap your dispatchers with a ContinuationInterceptor that reports all unresumed continuations as idling resources. But I'm not sure if that would handle cancellation.
z
the app needs to report idle only when all coroutines are suspended
but this doesn’t account for
delay(..)
or ongoing coroutines (actor coroutine)
I was able to get this working I think by creating a new
CoroutineDispatcher
that wrapped
Dispatchers.Default
and implemented an internal API for
Delay
The coroutines team needs to do a better job of providing APIs and clear guidance for Espresso idling in my opinion
obviously a non-trivial task too
r
@zak.taccardi I think the most common practice, if not the best practice is to use Idiling Resources. Than you can just focus on working with the counter, rather than the coroutine