Terminate observables on RPC connection failures (#2770)

This commit is contained in:
Thomas Schroeter
2018-03-13 10:01:44 +00:00
committed by GitHub
parent 568f7d7c17
commit 721728c8ab
2 changed files with 49 additions and 3 deletions

View File

@ -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
}