Fix dispatchResume.kt tests after suspendCoroutineOrReturn removal
To leave them COMMON_COROUTINES_TEST use suspendCoroutine instead But, since it requires for continuation to be called externally the tests are rewritten
This commit is contained in:
+20
-8
@@ -3,6 +3,7 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// COMMON_COROUTINES_TEST
|
// COMMON_COROUTINES_TEST
|
||||||
|
// FULL_JDK
|
||||||
import helpers.*
|
import helpers.*
|
||||||
import COROUTINES_PACKAGE.*
|
import COROUTINES_PACKAGE.*
|
||||||
import COROUTINES_PACKAGE.intrinsics.*
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
@@ -11,16 +12,20 @@ class Controller {
|
|||||||
var log = ""
|
var log = ""
|
||||||
var resumeIndex = 0
|
var resumeIndex = 0
|
||||||
|
|
||||||
suspend fun <T> suspendWithValue(value: T): T = suspendCoroutineOrReturn { continuation ->
|
var callback: (() -> Unit)? = null
|
||||||
|
|
||||||
|
suspend fun <T> suspendWithValue(value: T): T = suspendCoroutine { continuation ->
|
||||||
log += "suspend($value);"
|
log += "suspend($value);"
|
||||||
continuation.resume(value)
|
callback = {
|
||||||
COROUTINE_SUSPENDED
|
continuation.resume(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun suspendWithException(value: String): Unit = suspendCoroutineOrReturn { continuation ->
|
suspend fun suspendWithException(value: String): Unit = suspendCoroutine { continuation ->
|
||||||
log += "error($value);"
|
log += "error($value);"
|
||||||
continuation.resumeWithException(RuntimeException(value))
|
callback = {
|
||||||
COROUTINE_SUSPENDED
|
continuation.resumeWithException(RuntimeException(value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -71,6 +76,13 @@ fun test(c: suspend Controller.() -> Unit): String {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
while (controller.callback != null) {
|
||||||
|
val c = controller.callback!!
|
||||||
|
controller.callback = null
|
||||||
|
c()
|
||||||
|
}
|
||||||
|
|
||||||
return controller.log
|
return controller.log
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -80,7 +92,7 @@ fun box(): String {
|
|||||||
val k = suspendWithValue("K")
|
val k = suspendWithValue("K")
|
||||||
log += "$o$k;"
|
log += "$o$k;"
|
||||||
}
|
}
|
||||||
if (result != "before 0;suspend(O);before 1;suspend(K);before 2;OK;after 2;after 1;after 0;") return "fail1: $result"
|
if (result != "before 0;suspend(O);after 0;before 1;suspend(K);after 1;before 2;OK;after 2;") return "fail1: $result"
|
||||||
|
|
||||||
result = test {
|
result = test {
|
||||||
try {
|
try {
|
||||||
@@ -91,7 +103,7 @@ fun box(): String {
|
|||||||
log += "${e.message};"
|
log += "${e.message};"
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (result != "before 0;error(OK);before 1;OK;after 1;after 0;") return "fail2: $result"
|
if (result != "before 0;error(OK);after 0;before 1;OK;after 1;") return "fail2: $result"
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
+22
-10
@@ -3,6 +3,7 @@
|
|||||||
// WITH_RUNTIME
|
// WITH_RUNTIME
|
||||||
// WITH_COROUTINES
|
// WITH_COROUTINES
|
||||||
// COMMON_COROUTINES_TEST
|
// COMMON_COROUTINES_TEST
|
||||||
|
// FULL_JDK
|
||||||
import helpers.*
|
import helpers.*
|
||||||
import COROUTINES_PACKAGE.*
|
import COROUTINES_PACKAGE.*
|
||||||
import COROUTINES_PACKAGE.intrinsics.*
|
import COROUTINES_PACKAGE.intrinsics.*
|
||||||
@@ -11,16 +12,20 @@ class Controller {
|
|||||||
var log = ""
|
var log = ""
|
||||||
var resumeIndex = 0
|
var resumeIndex = 0
|
||||||
|
|
||||||
suspend fun <T> suspendWithValue(value: T): T = suspendCoroutineOrReturn { continuation ->
|
var callback: (() -> Unit)? = null
|
||||||
|
|
||||||
|
suspend fun <T> suspendWithValue(value: T): T = suspendCoroutine { continuation ->
|
||||||
log += "suspend($value);"
|
log += "suspend($value);"
|
||||||
continuation.resume(value)
|
callback = {
|
||||||
COROUTINE_SUSPENDED
|
continuation.resume(value)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
suspend fun suspendWithException(value: String): Unit = suspendCoroutineOrReturn { continuation ->
|
suspend fun suspendWithException(value: String): Unit = suspendCoroutine { continuation ->
|
||||||
log += "error($value);"
|
log += "error($value);"
|
||||||
continuation.resumeWithException(RuntimeException(value))
|
callback = {
|
||||||
COROUTINE_SUSPENDED
|
continuation.resumeWithException(RuntimeException(value))
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -31,8 +36,8 @@ abstract class ContinuationDispatcher : AbstractCoroutineContextElement(Continua
|
|||||||
}
|
}
|
||||||
|
|
||||||
private class DispatchedContinuation<T>(
|
private class DispatchedContinuation<T>(
|
||||||
val dispatcher: ContinuationDispatcher,
|
val dispatcher: ContinuationDispatcher,
|
||||||
val continuation: Continuation<T>
|
val continuation: Continuation<T>
|
||||||
): ContinuationAdapter<T>() {
|
): ContinuationAdapter<T>() {
|
||||||
override val context: CoroutineContext = continuation.context
|
override val context: CoroutineContext = continuation.context
|
||||||
|
|
||||||
@@ -71,6 +76,13 @@ fun test(c: suspend Controller.() -> Unit): String {
|
|||||||
return true
|
return true
|
||||||
}
|
}
|
||||||
}))
|
}))
|
||||||
|
|
||||||
|
while (controller.callback != null) {
|
||||||
|
val c = controller.callback!!
|
||||||
|
controller.callback = null
|
||||||
|
c()
|
||||||
|
}
|
||||||
|
|
||||||
return controller.log
|
return controller.log
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -98,12 +110,12 @@ fun box(): String {
|
|||||||
var result = test {
|
var result = test {
|
||||||
test1()
|
test1()
|
||||||
}
|
}
|
||||||
if (result != "before 0;suspend();before 1;suspend(O);before 2;suspend(K);before 3;OK;after 3;after 2;after 1;after 0;") return "fail1: $result"
|
if (result != "before 0;suspend();after 0;before 1;suspend(O);after 1;before 2;suspend(K);after 2;before 3;OK;after 3;") return "fail1: $result"
|
||||||
|
|
||||||
result = test {
|
result = test {
|
||||||
test2()
|
test2()
|
||||||
}
|
}
|
||||||
if (result != "before 0;suspend();before 1;suspend(O);before 2;error(OK);before 3;OK;after 3;after 2;after 1;after 0;") return "fail2: $result"
|
if (result != "before 0;suspend();after 0;before 1;suspend(O);after 1;before 2;error(OK);after 2;before 3;OK;after 3;") return "fail2: $result"
|
||||||
|
|
||||||
return "OK"
|
return "OK"
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user