Replace a couple of usages of suspendCoroutineOrReturn in tests

This commit is contained in:
Denis Zharkov
2018-07-04 18:40:14 +03:00
parent e753e0978f
commit a23ce42c80
2 changed files with 22 additions and 10 deletions
@@ -8,17 +8,22 @@ import COROUTINES_PACKAGE.*
import COROUTINES_PACKAGE.intrinsics.*
import kotlin.test.assertEquals
suspend fun suspendHere(): String = suspendCoroutineOrReturn { x ->
x.resume("OK")
COROUTINE_SUSPENDED
var callback: () -> Unit = {}
suspend fun suspendHere(): String = suspendCoroutine { x ->
callback = {
x.resume("OK")
}
}
suspend fun suspendWithException(): String = suspendCoroutineOrReturn { x ->
x.resumeWithException(RuntimeException("OK"))
COROUTINE_SUSPENDED
suspend fun suspendWithException(): String = suspendCoroutine { x ->
callback = {
x.resumeWithException(RuntimeException("OK"))
}
}
fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String): String {
callback = {}
var fromSuspension: String? = null
var counter = 0
@@ -39,6 +44,8 @@ fun builder(shouldSuspend: Boolean, expectedCount: Int, c: suspend () -> String)
"Exception: ${e.message}"
}
callback()
if (counter != expectedCount) throw RuntimeException("fail 0")
if (shouldSuspend) {