mirror of
https://github.com/corda/corda.git
synced 2025-06-23 01:19:00 +00:00
node: Add clock test for external interrupt on waiting strand
This commit is contained in:
@ -16,6 +16,7 @@ import java.util.concurrent.ExecutorService
|
|||||||
import java.util.concurrent.Executors
|
import java.util.concurrent.Executors
|
||||||
import kotlin.test.assertFalse
|
import kotlin.test.assertFalse
|
||||||
import kotlin.test.assertTrue
|
import kotlin.test.assertTrue
|
||||||
|
import kotlin.test.fail
|
||||||
|
|
||||||
class ClockUtilsTest {
|
class ClockUtilsTest {
|
||||||
|
|
||||||
@ -112,6 +113,27 @@ class ClockUtilsTest {
|
|||||||
assertFalse(testClock.awaitWithDeadline(advancedClock.instant(), future), "Should have reached deadline")
|
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
|
* 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:
|
* run on core module (in IntelliJ, open gradle side tab and run:
|
||||||
|
Reference in New Issue
Block a user