issue#64 Fix issue with idling resources

reference: https://github.com/JakeWharton/okhttp-idling-resource/pull/16
Espresso expects callback when a resource is released. However since our OkHttp Dispatchers were reused and 2 compiting IdlingResource was registered, one overwrote the other's callback and this crashed the Espresso tests.
To resolve this I made sure when one is registeres, it's respects the current callback and wraps around it instead of overwriting it.
This commit is contained in:
Gergely Hegedus 2022-03-07 17:09:56 +02:00
parent 963d16b3f9
commit 359904b5c3

View file

@ -19,7 +19,11 @@ class OkHttp3IdlingResource private constructor(
var callback: IdlingResource.ResourceCallback? = null
init {
dispatcher.idleCallback = Runnable { callback?.onTransitionToIdle() }
val currentCallback = dispatcher.idleCallback
dispatcher.idleCallback = Runnable {
callback?.onTransitionToIdle()
currentCallback?.run()
}
}
override fun getName(): String = name