Attempt for fix flaky debugger tests - wait for the resume before exit

This commit is contained in:
Nikolay Krasko
2017-06-20 16:25:39 +03:00
parent 233b63469a
commit 3ffd63a17c
13 changed files with 78 additions and 33 deletions
@@ -4,6 +4,8 @@ import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.CoroutineContext
import kotlin.coroutines.experimental.EmptyCoroutineContext
import kotlin.coroutines.experimental.startCoroutine
import java.util.concurrent.CountDownLatch
import java.util.concurrent.TimeUnit
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
companion object : EmptyContinuation()
@@ -14,3 +16,22 @@ open class EmptyContinuation(override val context: CoroutineContext = EmptyCorou
fun builder(c: suspend () -> Unit) {
c.startCoroutine(EmptyContinuation)
}
class WaitFinish(
private val timeout: Long = 5,
private val unit: TimeUnit = TimeUnit.SECONDS
) {
private val cdl = CountDownLatch(1)
fun finish() {
cdl.countDown()
}
fun waitEnd() {
if (!cdl.await(timeout, unit)) {
throw java.lang.IllegalStateException("Too long wait in debugger test!")
}
Thread.sleep(10)
}
}
@@ -1,18 +1,21 @@
package soSuspendableCallInEndOfFun
import forTests.builder
import forTests.WaitFinish
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine
private fun foo(a: Any) {}
val waiter = WaitFinish()
fun main(args: Array<String>) {
builder {
inFun()
}
foo("Main end")
Thread.sleep(100)
waiter.waitEnd()
}
suspend fun inFun() {
@@ -24,8 +27,9 @@ suspend fun inFun() {
suspend fun run() {
suspendCoroutine { cont: Continuation<Unit> ->
Thread {
cont.resume(Unit)
Thread.sleep(10)
cont.resume(Unit)
waiter.finish()
}.start()
}
}
@@ -1,11 +1,11 @@
LineBreakpoint created at soSuspendableCallInEndOfFun.kt:21
LineBreakpoint created at soSuspendableCallInEndOfFun.kt:24
Run Java
Connected to the target VM
soSuspendableCallInEndOfFun.kt:24
soSuspendableCallInEndOfFun.kt:21
soSuspendableCallInEndOfFun.kt:18
soSuspendableCallInEndOfFun.kt:22
soSuspendableCallInEndOfFun.kt:25
soSuspendableCallInEndOfFun.kt:-1
soSuspendableCallInEndOfFun.kt:28
soSuspendableCallInEndOfFun.kt:32
Disconnected from the target VM
Process finished with exit code 0
@@ -1,11 +1,14 @@
package soSuspendableCallInEndOfLambda
import forTests.builder
import forTests.WaitFinish
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine
private fun foo(a: Any) {}
val waiter = WaitFinish()
fun main(args: Array<String>) {
builder {
foo("Start")
@@ -14,14 +17,15 @@ fun main(args: Array<String>) {
}
foo("Main end")
Thread.sleep(100)
waiter.waitEnd()
}
suspend fun run() {
suspendCoroutine { cont: Continuation<Unit> ->
Thread {
cont.resume(Unit)
Thread.sleep(10)
cont.resume(Unit)
waiter.finish()
}.start()
}
}
@@ -1,9 +1,9 @@
LineBreakpoint created at soSuspendableCallInEndOfLambda.kt:13
LineBreakpoint created at soSuspendableCallInEndOfLambda.kt:16
Run Java
Connected to the target VM
soSuspendableCallInEndOfLambda.kt:16
soSuspendableCallInEndOfLambda.kt:13
soSuspendableCallInEndOfLambda.kt:10
soSuspendableCallInEndOfLambda.kt:14
soSuspendableCallInEndOfLambda.kt:17
Disconnected from the target VM
Process finished with exit code 0
@@ -1,18 +1,21 @@
package soSuspendableCallInFun
import forTests.builder
import forTests.WaitFinish
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine
private fun foo(a: Any) {}
val waiter = WaitFinish()
fun main(args: Array<String>) {
builder {
inFun()
}
foo("Main end")
Thread.sleep(100)
waiter.waitEnd()
}
suspend fun inFun() {
@@ -24,8 +27,9 @@ suspend fun inFun() {
suspend fun run() {
suspendCoroutine { cont: Continuation<Unit> ->
Thread {
cont.resume(Unit)
Thread.sleep(10)
cont.resume(Unit)
waiter.finish()
}.start()
}
}
@@ -1,9 +1,9 @@
LineBreakpoint created at soSuspendableCallInFun.kt:20
LineBreakpoint created at soSuspendableCallInFun.kt:23
Run Java
Connected to the target VM
soSuspendableCallInFun.kt:20
soSuspendableCallInFun.kt:18
soSuspendableCallInFun.kt:23
soSuspendableCallInFun.kt:21
soSuspendableCallInFun.kt:24
Disconnected from the target VM
Process finished with exit code 0
@@ -1,18 +1,21 @@
package soSuspendableCallInFunFromOtherStepping
import forTests.builder
import forTests.WaitFinish
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine
private fun foo(a: Any) {}
val waiter = WaitFinish()
fun main(args: Array<String>) {
builder {
inFun()
}
foo("Main end")
Thread.sleep(120)
waiter.waitEnd()
}
suspend fun inFun() {
@@ -25,8 +28,9 @@ suspend fun inFun() {
suspend fun run() {
return suspendCoroutine { cont: Continuation<Unit> ->
Thread {
cont.resume(Unit)
Thread.sleep(10)
cont.resume(Unit)
waiter.finish()
}.start()
}
}
@@ -1,10 +1,10 @@
LineBreakpoint created at soSuspendableCallInFunFromOtherStepping.kt:20
LineBreakpoint created at soSuspendableCallInFunFromOtherStepping.kt:23
Run Java
Connected to the target VM
soSuspendableCallInFunFromOtherStepping.kt:20
soSuspendableCallInFunFromOtherStepping.kt:23
soSuspendableCallInFunFromOtherStepping.kt:24
soSuspendableCallInFunFromOtherStepping.kt:21
soSuspendableCallInFunFromOtherStepping.kt:18
soSuspendableCallInFunFromOtherStepping.kt:22
soSuspendableCallInFunFromOtherStepping.kt:25
Disconnected from the target VM
Process finished with exit code 0
@@ -1,11 +1,14 @@
package soSuspendableCallInLambda
import forTests.builder
import forTests.WaitFinish
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine
private fun foo(a: Any) {}
val waiter = WaitFinish()
fun main(args: Array<String>) {
builder {
//Breakpoint!
@@ -14,14 +17,15 @@ fun main(args: Array<String>) {
}
foo("Main end")
Thread.sleep(100)
waiter.waitEnd()
}
suspend fun run() {
suspendCoroutine { cont: Continuation<Unit> ->
Thread {
cont.resume(Unit)
Thread.sleep(10)
cont.resume(Unit)
waiter.finish()
}.start()
}
}
@@ -1,9 +1,9 @@
LineBreakpoint created at soSuspendableCallInLambda.kt:12
LineBreakpoint created at soSuspendableCallInLambda.kt:15
Run Java
Connected to the target VM
soSuspendableCallInLambda.kt:12
soSuspendableCallInLambda.kt:10
soSuspendableCallInLambda.kt:15
soSuspendableCallInLambda.kt:13
soSuspendableCallInLambda.kt:16
Disconnected from the target VM
Process finished with exit code 0
@@ -1,18 +1,21 @@
package sofSuspendableCallInFun
import forTests.builder
import forTests.WaitFinish
import kotlin.coroutines.experimental.Continuation
import kotlin.coroutines.experimental.suspendCoroutine
private fun foo(a: Any) {}
val waiter = WaitFinish()
fun main(args: Array<String>) {
builder {
inFun()
}
foo("Main end")
Thread.sleep(100)
waiter.waitEnd()
}
suspend fun inFun() {
@@ -27,8 +30,9 @@ suspend fun run() {
suspendCoroutine { cont: Continuation<Unit> ->
Thread {
cont.resume(Unit)
Thread.sleep(10)
cont.resume(Unit)
waiter.finish()
}.start()
}
}
@@ -1,10 +1,10 @@
LineBreakpoint created at sofSuspendableCallInFun.kt:20
LineBreakpoint created at sofSuspendableCallInFun.kt:26
LineBreakpoint created at sofSuspendableCallInFun.kt:23
LineBreakpoint created at sofSuspendableCallInFun.kt:29
Run Java
Connected to the target VM
sofSuspendableCallInFun.kt:20
sofSuspendableCallInFun.kt:18
sofSuspendableCallInFun.kt:23
sofSuspendableCallInFun.kt:21
sofSuspendableCallInFun.kt:24
Disconnected from the target VM
Process finished with exit code 0