Skip to content

Commit 3ffd63a

Browse files
committed
Attempt for fix flaky debugger tests - wait for the resume before exit
1 parent 233b634 commit 3ffd63a

13 files changed

+78
-33
lines changed

idea/testData/debugger/tinyApp/src/forTests/coroutines.kt

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@ import kotlin.coroutines.experimental.Continuation
44
import kotlin.coroutines.experimental.CoroutineContext
55
import kotlin.coroutines.experimental.EmptyCoroutineContext
66
import kotlin.coroutines.experimental.startCoroutine
7+
import java.util.concurrent.CountDownLatch
8+
import java.util.concurrent.TimeUnit
79

810
open class EmptyContinuation(override val context: CoroutineContext = EmptyCoroutineContext) : Continuation<Any?> {
911
companion object : EmptyContinuation()
@@ -14,3 +16,22 @@ open class EmptyContinuation(override val context: CoroutineContext = EmptyCorou
1416
fun builder(c: suspend () -> Unit) {
1517
c.startCoroutine(EmptyContinuation)
1618
}
19+
20+
class WaitFinish(
21+
private val timeout: Long = 5,
22+
private val unit: TimeUnit = TimeUnit.SECONDS
23+
) {
24+
private val cdl = CountDownLatch(1)
25+
26+
fun finish() {
27+
cdl.countDown()
28+
}
29+
30+
fun waitEnd() {
31+
if (!cdl.await(timeout, unit)) {
32+
throw java.lang.IllegalStateException("Too long wait in debugger test!")
33+
}
34+
35+
Thread.sleep(10)
36+
}
37+
}

idea/testData/debugger/tinyApp/src/stepping/stepOver/soSuspendableCallInEndOfFun.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package soSuspendableCallInEndOfFun
22

33
import forTests.builder
4+
import forTests.WaitFinish
45
import kotlin.coroutines.experimental.Continuation
56
import kotlin.coroutines.experimental.suspendCoroutine
67

78
private fun foo(a: Any) {}
89

10+
val waiter = WaitFinish()
11+
912
fun main(args: Array<String>) {
1013
builder {
1114
inFun()
1215
}
1316

1417
foo("Main end")
15-
Thread.sleep(100)
18+
waiter.waitEnd()
1619
}
1720

1821
suspend fun inFun() {
@@ -24,8 +27,9 @@ suspend fun inFun() {
2427
suspend fun run() {
2528
suspendCoroutine { cont: Continuation<Unit> ->
2629
Thread {
27-
cont.resume(Unit)
2830
Thread.sleep(10)
31+
cont.resume(Unit)
32+
waiter.finish()
2933
}.start()
3034
}
3135
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
1-
LineBreakpoint created at soSuspendableCallInEndOfFun.kt:21
1+
LineBreakpoint created at soSuspendableCallInEndOfFun.kt:24
22
Run Java
33
Connected to the target VM
4+
soSuspendableCallInEndOfFun.kt:24
45
soSuspendableCallInEndOfFun.kt:21
5-
soSuspendableCallInEndOfFun.kt:18
6-
soSuspendableCallInEndOfFun.kt:22
6+
soSuspendableCallInEndOfFun.kt:25
77
soSuspendableCallInEndOfFun.kt:-1
8-
soSuspendableCallInEndOfFun.kt:28
8+
soSuspendableCallInEndOfFun.kt:32
99
Disconnected from the target VM
1010

1111
Process finished with exit code 0

idea/testData/debugger/tinyApp/src/stepping/stepOver/soSuspendableCallInEndOfLambda.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package soSuspendableCallInEndOfLambda
22

33
import forTests.builder
4+
import forTests.WaitFinish
45
import kotlin.coroutines.experimental.Continuation
56
import kotlin.coroutines.experimental.suspendCoroutine
67

78
private fun foo(a: Any) {}
89

10+
val waiter = WaitFinish()
11+
912
fun main(args: Array<String>) {
1013
builder {
1114
foo("Start")
@@ -14,14 +17,15 @@ fun main(args: Array<String>) {
1417
}
1518

1619
foo("Main end")
17-
Thread.sleep(100)
20+
waiter.waitEnd()
1821
}
1922

2023
suspend fun run() {
2124
suspendCoroutine { cont: Continuation<Unit> ->
2225
Thread {
23-
cont.resume(Unit)
2426
Thread.sleep(10)
27+
cont.resume(Unit)
28+
waiter.finish()
2529
}.start()
2630
}
2731
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
LineBreakpoint created at soSuspendableCallInEndOfLambda.kt:13
1+
LineBreakpoint created at soSuspendableCallInEndOfLambda.kt:16
22
Run Java
33
Connected to the target VM
4+
soSuspendableCallInEndOfLambda.kt:16
45
soSuspendableCallInEndOfLambda.kt:13
5-
soSuspendableCallInEndOfLambda.kt:10
6-
soSuspendableCallInEndOfLambda.kt:14
6+
soSuspendableCallInEndOfLambda.kt:17
77
Disconnected from the target VM
88

99
Process finished with exit code 0

idea/testData/debugger/tinyApp/src/stepping/stepOver/soSuspendableCallInFun.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package soSuspendableCallInFun
22

33
import forTests.builder
4+
import forTests.WaitFinish
45
import kotlin.coroutines.experimental.Continuation
56
import kotlin.coroutines.experimental.suspendCoroutine
67

78
private fun foo(a: Any) {}
89

10+
val waiter = WaitFinish()
11+
912
fun main(args: Array<String>) {
1013
builder {
1114
inFun()
1215
}
1316

1417
foo("Main end")
15-
Thread.sleep(100)
18+
waiter.waitEnd()
1619
}
1720

1821
suspend fun inFun() {
@@ -24,8 +27,9 @@ suspend fun inFun() {
2427
suspend fun run() {
2528
suspendCoroutine { cont: Continuation<Unit> ->
2629
Thread {
27-
cont.resume(Unit)
2830
Thread.sleep(10)
31+
cont.resume(Unit)
32+
waiter.finish()
2933
}.start()
3034
}
3135
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
LineBreakpoint created at soSuspendableCallInFun.kt:20
1+
LineBreakpoint created at soSuspendableCallInFun.kt:23
22
Run Java
33
Connected to the target VM
4-
soSuspendableCallInFun.kt:20
5-
soSuspendableCallInFun.kt:18
4+
soSuspendableCallInFun.kt:23
65
soSuspendableCallInFun.kt:21
6+
soSuspendableCallInFun.kt:24
77
Disconnected from the target VM
88

99
Process finished with exit code 0

idea/testData/debugger/tinyApp/src/stepping/stepOver/soSuspendableCallInFunFromOtherStepping.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package soSuspendableCallInFunFromOtherStepping
22

33
import forTests.builder
4+
import forTests.WaitFinish
45
import kotlin.coroutines.experimental.Continuation
56
import kotlin.coroutines.experimental.suspendCoroutine
67

78
private fun foo(a: Any) {}
89

10+
val waiter = WaitFinish()
11+
912
fun main(args: Array<String>) {
1013
builder {
1114
inFun()
1215
}
1316

1417
foo("Main end")
15-
Thread.sleep(120)
18+
waiter.waitEnd()
1619
}
1720

1821
suspend fun inFun() {
@@ -25,8 +28,9 @@ suspend fun inFun() {
2528
suspend fun run() {
2629
return suspendCoroutine { cont: Continuation<Unit> ->
2730
Thread {
28-
cont.resume(Unit)
2931
Thread.sleep(10)
32+
cont.resume(Unit)
33+
waiter.finish()
3034
}.start()
3135
}
3236
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
LineBreakpoint created at soSuspendableCallInFunFromOtherStepping.kt:20
1+
LineBreakpoint created at soSuspendableCallInFunFromOtherStepping.kt:23
22
Run Java
33
Connected to the target VM
4-
soSuspendableCallInFunFromOtherStepping.kt:20
4+
soSuspendableCallInFunFromOtherStepping.kt:23
5+
soSuspendableCallInFunFromOtherStepping.kt:24
56
soSuspendableCallInFunFromOtherStepping.kt:21
6-
soSuspendableCallInFunFromOtherStepping.kt:18
7-
soSuspendableCallInFunFromOtherStepping.kt:22
7+
soSuspendableCallInFunFromOtherStepping.kt:25
88
Disconnected from the target VM
99

1010
Process finished with exit code 0

idea/testData/debugger/tinyApp/src/stepping/stepOver/soSuspendableCallInLambda.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,14 @@
11
package soSuspendableCallInLambda
22

33
import forTests.builder
4+
import forTests.WaitFinish
45
import kotlin.coroutines.experimental.Continuation
56
import kotlin.coroutines.experimental.suspendCoroutine
67

78
private fun foo(a: Any) {}
89

10+
val waiter = WaitFinish()
11+
912
fun main(args: Array<String>) {
1013
builder {
1114
//Breakpoint!
@@ -14,14 +17,15 @@ fun main(args: Array<String>) {
1417
}
1518

1619
foo("Main end")
17-
Thread.sleep(100)
20+
waiter.waitEnd()
1821
}
1922

2023
suspend fun run() {
2124
suspendCoroutine { cont: Continuation<Unit> ->
2225
Thread {
23-
cont.resume(Unit)
2426
Thread.sleep(10)
27+
cont.resume(Unit)
28+
waiter.finish()
2529
}.start()
2630
}
2731
}
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
LineBreakpoint created at soSuspendableCallInLambda.kt:12
1+
LineBreakpoint created at soSuspendableCallInLambda.kt:15
22
Run Java
33
Connected to the target VM
4-
soSuspendableCallInLambda.kt:12
5-
soSuspendableCallInLambda.kt:10
4+
soSuspendableCallInLambda.kt:15
65
soSuspendableCallInLambda.kt:13
6+
soSuspendableCallInLambda.kt:16
77
Disconnected from the target VM
88

99
Process finished with exit code 0

idea/testData/debugger/tinyApp/src/stepping/stepOverForce/sofSuspendableCallInFun.kt

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,18 +1,21 @@
11
package sofSuspendableCallInFun
22

33
import forTests.builder
4+
import forTests.WaitFinish
45
import kotlin.coroutines.experimental.Continuation
56
import kotlin.coroutines.experimental.suspendCoroutine
67

78
private fun foo(a: Any) {}
89

10+
val waiter = WaitFinish()
11+
912
fun main(args: Array<String>) {
1013
builder {
1114
inFun()
1215
}
1316

1417
foo("Main end")
15-
Thread.sleep(100)
18+
waiter.waitEnd()
1619
}
1720

1821
suspend fun inFun() {
@@ -27,8 +30,9 @@ suspend fun run() {
2730

2831
suspendCoroutine { cont: Continuation<Unit> ->
2932
Thread {
30-
cont.resume(Unit)
3133
Thread.sleep(10)
34+
cont.resume(Unit)
35+
waiter.finish()
3236
}.start()
3337
}
3438
}
Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
1-
LineBreakpoint created at sofSuspendableCallInFun.kt:20
2-
LineBreakpoint created at sofSuspendableCallInFun.kt:26
1+
LineBreakpoint created at sofSuspendableCallInFun.kt:23
2+
LineBreakpoint created at sofSuspendableCallInFun.kt:29
33
Run Java
44
Connected to the target VM
5-
sofSuspendableCallInFun.kt:20
6-
sofSuspendableCallInFun.kt:18
5+
sofSuspendableCallInFun.kt:23
76
sofSuspendableCallInFun.kt:21
7+
sofSuspendableCallInFun.kt:24
88
Disconnected from the target VM
99

1010
Process finished with exit code 0

0 commit comments

Comments
 (0)