Timeline: fix some tests and a one more
This commit is contained in:
parent
b9676c1ec0
commit
f80f6f5bd9
9 changed files with 137 additions and 54 deletions
|
|
@ -16,7 +16,12 @@
|
|||
|
||||
package io.element.android.tests.testutils
|
||||
|
||||
import kotlinx.coroutines.CompletableDeferred
|
||||
import kotlinx.coroutines.TimeoutCancellationException
|
||||
import kotlinx.coroutines.delay
|
||||
import kotlinx.coroutines.withTimeout
|
||||
import kotlin.time.Duration
|
||||
import kotlin.time.Duration.Companion.milliseconds
|
||||
|
||||
/**
|
||||
* Workaround for https://github.com/cashapp/molecule/issues/249.
|
||||
|
|
@ -26,3 +31,18 @@ suspend inline fun <T> simulateLongTask(lambda: () -> T): T {
|
|||
delay(1)
|
||||
return lambda()
|
||||
}
|
||||
|
||||
/**
|
||||
* Can be used for testing events in Presenter, where the event does not emit new state.
|
||||
* If the (virtual) timeout is passed, we release the latch manually.
|
||||
*/
|
||||
suspend fun awaitWithLatch(timeout: Duration = 300.milliseconds, block: (CompletableDeferred<Unit>) -> Unit) {
|
||||
val latch = CompletableDeferred<Unit>()
|
||||
try {
|
||||
withTimeout(timeout) {
|
||||
latch.also(block).await()
|
||||
}
|
||||
} catch (exception: TimeoutCancellationException) {
|
||||
latch.complete(Unit)
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue