Skip to content

Commit c5b7a64

Browse files
committed
Ensure that interruption flag is cleaned up properly
Fixes #1691
1 parent 1c7f2b7 commit c5b7a64

File tree

1 file changed

+25
-1
lines changed

1 file changed

+25
-1
lines changed

kotlinx-coroutines-core/jvm/test/scheduling/CoroutineSchedulerTest.kt

+25-1
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,11 @@
55
package kotlinx.coroutines.scheduling
66

77
import kotlinx.coroutines.*
8-
import org.junit.*
8+
import org.junit.Test
99
import java.lang.Runnable
1010
import java.util.concurrent.*
1111
import kotlin.coroutines.*
12+
import kotlin.test.*
1213

1314
class CoroutineSchedulerTest : TestBase() {
1415

@@ -127,6 +128,29 @@ class CoroutineSchedulerTest : TestBase() {
127128
latch.await()
128129
}
129130

131+
@Test
132+
fun testInterruptionCleanup() {
133+
ExperimentalCoroutineDispatcher(1, 1).use {
134+
val executor = it.executor
135+
var latch = CountDownLatch(1)
136+
executor.execute {
137+
Thread.currentThread().interrupt()
138+
latch.countDown()
139+
}
140+
latch.await()
141+
Thread.sleep(100) // I am really sorry
142+
latch = CountDownLatch(1)
143+
executor.execute {
144+
try {
145+
assertFalse(Thread.currentThread().isInterrupted)
146+
} finally {
147+
latch.countDown()
148+
}
149+
}
150+
latch.await()
151+
}
152+
}
153+
130154
private fun testUniformDistribution(worker: CoroutineScheduler.Worker, bound: Int) {
131155
val result = IntArray(bound)
132156
val iterations = 10_000_000

0 commit comments

Comments
 (0)