Skip to content

Commit

Permalink
Ensure that interruption flag is cleaned up properly
Browse files Browse the repository at this point in the history
  • Loading branch information
qwwdfsad committed Dec 12, 2019
1 parent 966020e commit 4dcfced
Showing 1 changed file with 25 additions and 1 deletion.
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

0 comments on commit 4dcfced

Please sign in to comment.