node: Add clock test for external interrupt on waiting strand

This commit is contained in:
Andras Slemmer 2016-09-05 17:42:07 +01:00
parent fc7000c152
commit 737fc0589c

View File

@ -16,6 +16,7 @@ import java.util.concurrent.ExecutorService
import java.util.concurrent.Executors
import kotlin.test.assertFalse
import kotlin.test.assertTrue
import kotlin.test.fail
class ClockUtilsTest {
@ -112,6 +113,27 @@ class ClockUtilsTest {
assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline")
}
@Test
fun `test external interrupt of a clock future`() {
val mainStrand = Strand.currentStrand()
executor.execute @Suspendable {
// Wait until main thread is waiting
while (mainStrand.state != Strand.State.TIMED_WAITING) {
Strand.sleep(1)
}
mainStrand.interrupt()
}
val testClock = TestClock(stoppedClock)
val advancedClock = Clock.offset(stoppedClock, Duration.ofHours(10))
try {
testClock.awaitWithDeadline(advancedClock.instant(), SettableFuture.create<Boolean>())
fail("Expected InterruptedException")
} catch (exception: InterruptedException) {
}
}
/**
* If this test seems to hang and throw an NPE, then likely that quasar suspendables scanner has not been
* run on core module (in IntelliJ, open gradle side tab and run: