Issue#67 Extract ActivityScenario.safeClose into separate module

This commit is contained in:
Gergely Hegedus 2022-05-27 15:12:59 +03:00
parent 689aee9702
commit 1c0153db75
8 changed files with 15 additions and 9 deletions

View file

@ -31,4 +31,5 @@ android {
dependencies {
implementation "org.jetbrains.kotlinx:kotlinx-coroutines-test:$coroutines_version"
implementation "androidx.test:core:$androidx_test_version"
}

View file

@ -0,0 +1,27 @@
package org.fnives.test.showcase.android.testutil.activity
import android.app.Activity
import androidx.test.core.app.ActivityScenario
/**
* Workaround for issue: https://github.com/android/android-test/issues/676.
*
* Call this instead of ActivityScenario.close().
*/
fun <T : Activity> ActivityScenario<T>.safeClose() {
workaroundForActivityScenarioCLoseLockingUp()
close()
}
/**
* This should not be needed, we shouldn't use sleep basically ever.
* However, it seems to be and issue described here: https://github.com/android/android-test/issues/676
*
* If an activity is finished in code, the ActivityScenario.close() can hang 30 to 45 seconds.
* This sleep let's the Activity finish it's state change and unlocks the ActivityScenario.
*
* As soon as that issue is closed, this should be removed as well.
*/
private fun workaroundForActivityScenarioCLoseLockingUp() {
Thread.sleep(1000L)
}