issue#116 Adjustments for timing of Delay

This is required because otherwise clicks could become Long clicks
This commit is contained in:
Gergely Hegedus 2022-07-20 18:43:33 +03:00
parent d057c357a3
commit fd661ca13d
2 changed files with 12 additions and 10 deletions

View file

@ -6,11 +6,18 @@ import org.fnives.test.showcase.android.testutil.synchronization.loopMainThreadF
import java.util.concurrent.Executors
// workaround, issue with idlingResources is tracked here https://github.com/robolectric/robolectric/issues/4807
fun anyResourceNotIdle(): Boolean = (!IdlingRegistry.getInstance().resources.all(IdlingResource::isIdleNow))
fun anyResourceNotIdle(): Boolean {
val anyResourceNotIdle = (!IdlingRegistry.getInstance().resources.all(IdlingResource::isIdleNow))
if (!anyResourceNotIdle) {
// once it's idle we wait the Idling resource's time
OkHttp3IdlingResource.sleepForDispatcherDefaultCallInRetrofitErrorState()
}
return anyResourceNotIdle
}
fun awaitIdlingResources() {
if (!anyResourceNotIdle()) return
val idlingRegistry = IdlingRegistry.getInstance()
if (idlingRegistry.resources.all(IdlingResource::isIdleNow)) return
val executor = Executors.newSingleThreadExecutor()
var isIdle = false
@ -22,6 +29,7 @@ fun awaitIdlingResources() {
idlingResource.awaitUntilIdle()
}
} while (!idlingRegistry.resources.all(IdlingResource::isIdleNow))
OkHttp3IdlingResource.sleepForDispatcherDefaultCallInRetrofitErrorState()
isIdle = true
}
while (!isIdle) {

View file

@ -29,13 +29,7 @@ class OkHttp3IdlingResource private constructor(
override fun getName(): String = name
override fun isIdleNow(): Boolean {
val isIdle = dispatcher.runningCallsCount() == 0
if (isIdle) {
sleepForDispatcherDefaultCallInRetrofitErrorState()
}
return isIdle
}
override fun isIdleNow(): Boolean = dispatcher.runningCallsCount() == 0
override fun registerIdleTransitionCallback(callback: IdlingResource.ResourceCallback?) {
this.callback = callback
@ -65,7 +59,7 @@ class OkHttp3IdlingResource private constructor(
*
* This brings us to this sleep for now.
*/
private fun sleepForDispatcherDefaultCallInRetrofitErrorState() {
fun sleepForDispatcherDefaultCallInRetrofitErrorState() {
Thread.sleep(200L)
}
}