1
1
/*
2
- * Copyright 2016-2018 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
2
+ * Copyright 2016-2019 JetBrains s.r.o. Use of this source code is governed by the Apache 2.0 license.
3
3
*/
4
4
5
5
package kotlinx.coroutines.debug
@@ -11,6 +11,7 @@ import kotlin.test.*
11
11
12
12
class CoroutinesDumpTest : DebugTestBase () {
13
13
private val monitor = Any ()
14
+ private var coroutineStarted = false // guarded by monitor
14
15
15
16
@Test
16
17
fun testSuspendedCoroutine () = synchronized(monitor) {
@@ -130,7 +131,7 @@ class CoroutinesDumpTest : DebugTestBase() {
130
131
131
132
private suspend fun nestedActiveMethod (shouldSuspend : Boolean ) {
132
133
if (shouldSuspend) yield ()
133
- notifyTest ()
134
+ notifyCoroutineStarted ()
134
135
while (coroutineContext[Job ]!! .isActive) {
135
136
Thread .sleep(100 )
136
137
}
@@ -143,17 +144,18 @@ class CoroutinesDumpTest : DebugTestBase() {
143
144
144
145
private suspend fun sleepingNestedMethod () {
145
146
yield ()
146
- notifyTest ()
147
+ notifyCoroutineStarted ()
147
148
delay(Long .MAX_VALUE )
148
149
}
149
150
150
151
private fun awaitCoroutineStarted () {
151
- (monitor as Object ).wait()
152
+ while ( ! coroutineStarted) (monitor as Object ).wait()
152
153
}
153
154
154
- private fun notifyTest () {
155
+ private fun notifyCoroutineStarted () {
155
156
synchronized(monitor) {
156
- (monitor as Object ).notify()
157
+ coroutineStarted = true
158
+ (monitor as Object ).notifyAll()
157
159
}
158
160
}
159
161
}
0 commit comments