mirror of
https://github.com/corda/corda.git
synced 2025-01-18 18:56:28 +00:00
node: Add clock test for external interrupt on waiting strand
This commit is contained in:
parent
fc7000c152
commit
737fc0589c
@ -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:
|
||||
|
Loading…
Reference in New Issue
Block a user