File tree 1 file changed +28
-0
lines changed
kotlinx-coroutines-core/common/test
1 file changed +28
-0
lines changed Original file line number Diff line number Diff line change 6
6
7
7
package kotlinx.coroutines
8
8
9
+ import kotlinx.coroutines.internal.*
9
10
import kotlin.coroutines.*
10
11
import kotlin.test.*
11
12
@@ -159,4 +160,31 @@ class CancellableContinuationHandlersTest : TestBase() {
159
160
}
160
161
finish(3 )
161
162
}
163
+
164
+ @Test
165
+ fun testSegmentAsHandler () = runTest {
166
+ class MySegment : Segment <MySegment >(0 , null , 0 ) {
167
+ override val maxSlots: Int get() = 0
168
+
169
+ var invokeOnCancellationCalled = false
170
+ override fun invokeOnCancellation (index : Int , cause : Throwable ? ) {
171
+ invokeOnCancellationCalled = true
172
+ }
173
+ }
174
+ val s = MySegment ()
175
+ expect(1 )
176
+ try {
177
+ suspendCancellableCoroutine<Unit > { c ->
178
+ expect(2 )
179
+ c as CancellableContinuationImpl <* >
180
+ c.invokeOnCancellation(s, 0 )
181
+ c.cancel()
182
+ }
183
+ } catch (e: CancellationException ) {
184
+ expect(3 )
185
+ }
186
+ expect(4 )
187
+ check(s.invokeOnCancellationCalled)
188
+ finish(5 )
189
+ }
162
190
}
You can’t perform that action at this time.
0 commit comments