Skip to content

Commit aeeea94

Browse files
committed
Let's see how it works :)
1 parent a1bf13f commit aeeea94

File tree

1 file changed

+28
-0
lines changed

1 file changed

+28
-0
lines changed

kotlinx-coroutines-core/common/test/CancellableContinuationHandlersTest.kt

+28
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66

77
package kotlinx.coroutines
88

9+
import kotlinx.coroutines.internal.*
910
import kotlin.coroutines.*
1011
import kotlin.test.*
1112

@@ -159,4 +160,31 @@ class CancellableContinuationHandlersTest : TestBase() {
159160
}
160161
finish(3)
161162
}
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+
}
162190
}

0 commit comments

Comments
 (0)