mirror of
https://github.com/corda/corda.git
synced 2025-06-21 08:40:03 +00:00
Terminate observables on RPC connection failures (#2770)
This commit is contained in:
@ -316,6 +316,46 @@ class RPCStabilityTests {
|
||||
}
|
||||
}
|
||||
|
||||
interface NoOps : RPCOps {
|
||||
fun subscribe(): Observable<Nothing>
|
||||
}
|
||||
|
||||
@Test
|
||||
fun `observables error when connection breaks`() {
|
||||
rpcDriver {
|
||||
val ops = object : NoOps {
|
||||
override val protocolVersion = 0
|
||||
override fun subscribe(): Observable<Nothing> {
|
||||
return PublishSubject.create<Nothing>()
|
||||
}
|
||||
}
|
||||
val serverFollower = shutdownManager.follower()
|
||||
val serverPort = startRpcServer<NoOps>(ops = ops).getOrThrow().broker.hostAndPort!!
|
||||
serverFollower.unfollow()
|
||||
|
||||
val clientConfiguration = RPCClientConfiguration.default.copy(connectionRetryInterval = 500.millis, maxReconnectAttempts = 1)
|
||||
val clientFollower = shutdownManager.follower()
|
||||
val client = startRpcClient<NoOps>(serverPort, configuration = clientConfiguration).getOrThrow()
|
||||
clientFollower.unfollow()
|
||||
|
||||
var terminateHandlerCalled = false
|
||||
var errorHandlerCalled = false
|
||||
val subscription = client.subscribe()
|
||||
.doOnTerminate{ terminateHandlerCalled = true }
|
||||
.doOnError { errorHandlerCalled = true }
|
||||
.subscribe()
|
||||
|
||||
serverFollower.shutdown()
|
||||
Thread.sleep(100)
|
||||
|
||||
assertTrue(terminateHandlerCalled)
|
||||
assertTrue(errorHandlerCalled)
|
||||
assertTrue(subscription.isUnsubscribed)
|
||||
|
||||
clientFollower.shutdown() // Driver would do this after the new server, causing hang.
|
||||
}
|
||||
}
|
||||
|
||||
interface ThreadOps : RPCOps {
|
||||
fun sendMessage(id: Int, msgNo: Int): String
|
||||
}
|
||||
|
Reference in New Issue
Block a user