Skip to content
Prev Previous commit
Next Next commit
Ensure that interruption flag is cleaned up properly
Fixes #1691
  • Loading branch information
qwwdfsad committed Dec 12, 2019
commit 4dcfced70ea5efd69a12d258ef5edc33a1129b44
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,11 @@
package kotlinx.coroutines.scheduling

import kotlinx.coroutines.*
import org.junit.*
import org.junit.Test
import java.lang.Runnable
import java.util.concurrent.*
import kotlin.coroutines.*
import kotlin.test.*

class CoroutineSchedulerTest : TestBase() {

Expand Down Expand Up @@ -127,6 +128,29 @@ class CoroutineSchedulerTest : TestBase() {
latch.await()
}

@Test
fun testInterruptionCleanup() {
ExperimentalCoroutineDispatcher(1, 1).use {
val executor = it.executor
var latch = CountDownLatch(1)
executor.execute {
Thread.currentThread().interrupt()
latch.countDown()
}
latch.await()
Thread.sleep(100) // I am really sorry
latch = CountDownLatch(1)
executor.execute {
try {
assertFalse(Thread.currentThread().isInterrupted)
} finally {
latch.countDown()
}
}
latch.await()
}
}

private fun testUniformDistribution(worker: CoroutineScheduler.Worker, bound: Int) {
val result = IntArray(bound)
val iterations = 10_000_000
Expand Down