@@ -7,6 +7,7 @@ package definitely.not.kotlinx.coroutines
7
7
8
8
import kotlinx.coroutines.*
9
9
import kotlinx.coroutines.debug.*
10
+ import kotlinx.coroutines.selects.*
10
11
import org.junit.*
11
12
import org.junit.Test
12
13
import java.util.concurrent.*
@@ -83,6 +84,48 @@ class SanitizedProbesTest : TestBase() {
83
84
deferred.cancelAndJoin()
84
85
}
85
86
87
+ @Test
88
+ fun testSelectBuilder () = runTest {
89
+ val selector = launchSelector()
90
+ expect(1 )
91
+ yield ()
92
+ expect(3 )
93
+ verifyDump(" Coroutine \" coroutine#1\" :BlockingCoroutine{Active}@35fc6dc4, state: RUNNING (Last suspension stacktrace, not an actual stacktrace)\n " +
94
+ " \t (Coroutine creation stacktrace)\n " +
95
+ " \t at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.createCoroutineUnintercepted(IntrinsicsJvm.kt:116)" ,
96
+
97
+ " Coroutine \" coroutine#2\" :StandaloneCoroutine{Active}@1b68b9a4, state: SUSPENDED\n " +
98
+ " \t at definitely.not.kotlinx.coroutines.SanitizedProbesTest\$ launchSelector\$ 1\$ 1\$ 1.invokeSuspend(SanitizedProbesTest.kt:105)\n " +
99
+ " \t at definitely.not.kotlinx.coroutines.SanitizedProbesTest\$ launchSelector\$ 1.invokeSuspend(SanitizedProbesTest.kt:143)\n " +
100
+ " \t (Coroutine creation stacktrace)\n " +
101
+ " \t at kotlin.coroutines.intrinsics.IntrinsicsKt__IntrinsicsJvmKt.createCoroutineUnintercepted(IntrinsicsJvm.kt:116)\n " +
102
+ " \t at kotlinx.coroutines.intrinsics.CancellableKt.startCoroutineCancellable(Cancellable.kt:25)\n " +
103
+ " \t at kotlinx.coroutines.BuildersKt.launch\$ default(Unknown Source)\n " +
104
+ " \t at definitely.not.kotlinx.coroutines.SanitizedProbesTest.launchSelector(SanitizedProbesTest.kt:100)\n " +
105
+ " \t at definitely.not.kotlinx.coroutines.SanitizedProbesTest.access\$ launchSelector(SanitizedProbesTest.kt:16)\n " +
106
+ " \t at definitely.not.kotlinx.coroutines.SanitizedProbesTest\$ testSelectBuilder\$ 1.invokeSuspend(SanitizedProbesTest.kt:89)\n " +
107
+ " \t at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:32)\n " +
108
+ " \t at kotlinx.coroutines.DispatchedTask.run(Dispatched.kt:233)\n " +
109
+ " \t at kotlinx.coroutines.TestBase.runTest\$ default(TestBase.kt:154)\n " +
110
+ " \t at definitely.not.kotlinx.coroutines.SanitizedProbesTest.testSelectBuilder(SanitizedProbesTest.kt:88)" )
111
+ finish(4 )
112
+ selector.cancelAndJoin()
113
+ }
114
+
115
+ private fun CoroutineScope.launchSelector (): Job {
116
+ val job = CompletableDeferred (Unit )
117
+ return launch {
118
+ select<Int > {
119
+ job.onJoin {
120
+ expect(2 )
121
+ delay(Long .MAX_VALUE )
122
+ 1
123
+ }
124
+
125
+ }
126
+ }
127
+ }
128
+
86
129
private fun CoroutineScope.createActiveDeferred (): Deferred <* > = async {
87
130
suspendingMethod()
88
131
assertTrue(true )
0 commit comments